aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2009-10-09 21:02:56 +0000
committerPeter Eisentraut <peter_e@gmx.net>2009-10-09 21:02:56 +0000
commitb865d2758255b767e30dc5f23c7c7d209e716f3b (patch)
tree7df91d80adfc7de9040c7446ea87d319a2e18a57 /src/backend/utils/adt/ruleutils.c
parentc970292a94e0fff468d500db430d751b6221a0b4 (diff)
downloadpostgresql-b865d2758255b767e30dc5f23c7c7d209e716f3b.tar.gz
postgresql-b865d2758255b767e30dc5f23c7c7d209e716f3b.zip
Use pg_get_triggerdef in pg_dump
Add a variant of pg_get_triggerdef with a second argument "pretty" that causes the output to be formatted in the way pg_dump used to do. Use this variant in pg_dump with server versions >= 8.5. This insulates pg_dump from most future trigger feature additions, such as the upcoming column triggers patch. Author: Itagaki Takahiro <itagaki.takahiro@oss.ntt.co.jp>
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 4c04bafd7c6..d88d8f22f32 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.307 2009/10/08 02:39:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.308 2009/10/09 21:02:55 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -139,6 +139,7 @@ static char *deparse_expression_pretty(Node *expr, List *dpcontext,
bool forceprefix, bool showimplicit,
int prettyFlags, int startIndent);
static char *pg_get_viewdef_worker(Oid viewoid, int prettyFlags);
+static char *pg_get_triggerdef_worker(Oid trigid, bool pretty);
static void decompile_column_index_array(Datum column_index_array, Oid relId,
StringInfo buf);
static char *pg_get_ruledef_worker(Oid ruleoid, int prettyFlags);
@@ -462,6 +463,22 @@ Datum
pg_get_triggerdef(PG_FUNCTION_ARGS)
{
Oid trigid = PG_GETARG_OID(0);
+
+ PG_RETURN_TEXT_P(string_to_text(pg_get_triggerdef_worker(trigid, false)));
+}
+
+Datum
+pg_get_triggerdef_ext(PG_FUNCTION_ARGS)
+{
+ Oid trigid = PG_GETARG_OID(0);
+ bool pretty = PG_GETARG_BOOL(1);
+
+ PG_RETURN_TEXT_P(string_to_text(pg_get_triggerdef_worker(trigid, pretty)));
+}
+
+static char *
+pg_get_triggerdef_worker(Oid trigid, bool pretty)
+{
HeapTuple ht_trig;
Form_pg_trigger trigrec;
StringInfoData buf;
@@ -498,9 +515,10 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
initStringInfo(&buf);
tgname = NameStr(trigrec->tgname);
- appendStringInfo(&buf, "CREATE %sTRIGGER %s ",
+ appendStringInfo(&buf, "CREATE %sTRIGGER %s",
trigrec->tgisconstraint ? "CONSTRAINT " : "",
quote_identifier(tgname));
+ appendStringInfoString(&buf, pretty ? "\n " : " ");
if (TRIGGER_FOR_BEFORE(trigrec->tgtype))
appendStringInfo(&buf, "BEFORE");
@@ -533,29 +551,33 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
else
appendStringInfo(&buf, " TRUNCATE");
}
- appendStringInfo(&buf, " ON %s ",
+ appendStringInfo(&buf, " ON %s",
generate_relation_name(trigrec->tgrelid, NIL));
+ appendStringInfoString(&buf, pretty ? "\n " : " ");
if (trigrec->tgisconstraint)
{
if (trigrec->tgconstrrelid != InvalidOid)
- appendStringInfo(&buf, "FROM %s ",
- generate_relation_name(trigrec->tgconstrrelid,
- NIL));
+ {
+ appendStringInfo(&buf, "FROM %s",
+ generate_relation_name(trigrec->tgconstrrelid, NIL));
+ appendStringInfoString(&buf, pretty ? "\n " : " ");
+ }
if (!trigrec->tgdeferrable)
appendStringInfo(&buf, "NOT ");
appendStringInfo(&buf, "DEFERRABLE INITIALLY ");
if (trigrec->tginitdeferred)
- appendStringInfo(&buf, "DEFERRED ");
+ appendStringInfo(&buf, "DEFERRED");
else
- appendStringInfo(&buf, "IMMEDIATE ");
-
+ appendStringInfo(&buf, "IMMEDIATE");
+ appendStringInfoString(&buf, pretty ? "\n " : " ");
}
if (TRIGGER_FOR_ROW(trigrec->tgtype))
- appendStringInfo(&buf, "FOR EACH ROW ");
+ appendStringInfo(&buf, "FOR EACH ROW");
else
- appendStringInfo(&buf, "FOR EACH STATEMENT ");
+ appendStringInfo(&buf, "FOR EACH STATEMENT");
+ appendStringInfoString(&buf, pretty ? "\n " : " ");
appendStringInfo(&buf, "EXECUTE PROCEDURE %s(",
generate_function_name(trigrec->tgfoid, 0,
@@ -594,7 +616,7 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
heap_close(tgrel, AccessShareLock);
- PG_RETURN_TEXT_P(string_to_text(buf.data));
+ return buf.data;
}
/* ----------