Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb865d27

Browse files
committed
Use pg_get_triggerdef in pg_dump
Add a variant of pg_get_triggerdef with a second argument "pretty" thatcauses the output to be formatted in the way pg_dump used to do. Use thisvariant in pg_dump with server versions >= 8.5.This insulates pg_dump from most future trigger feature additions, such asthe upcoming column triggers patch.Author: Itagaki Takahiro <itagaki.takahiro@oss.ntt.co.jp>
1 parentc970292 commitb865d27

File tree

7 files changed

+196
-135
lines changed

7 files changed

+196
-135
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.487 2009/08/16 19:55:21 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.488 2009/10/09 21:02:55 petere Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -12369,6 +12369,11 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
1236912369
<entry><type>text</type></entry>
1237012370
<entry>get <command>CREATE [ CONSTRAINT ] TRIGGER</> command for trigger</entry>
1237112371
</row>
12372+
<row>
12373+
<entry><function>pg_get_triggerdef</function>(<parameter>trigger_oid</parameter>, <parameter>pretty_bool</>)</entry>
12374+
<entry><type>text</type></entry>
12375+
<entry>get <command>CREATE [ CONSTRAINT ] TRIGGER</> command for trigger</entry>
12376+
</row>
1237212377
<row>
1237312378
<entry><literal><function>pg_get_userbyid</function>(<parameter>role_oid</parameter>)</literal></entry>
1237412379
<entry><type>name</type></entry>

‎src/backend/utils/adt/ruleutils.c

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.307 2009/10/0802:39:23 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.308 2009/10/09 21:02:55 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -139,6 +139,7 @@ static char *deparse_expression_pretty(Node *expr, List *dpcontext,
139139
boolforceprefix,boolshowimplicit,
140140
intprettyFlags,intstartIndent);
141141
staticchar*pg_get_viewdef_worker(Oidviewoid,intprettyFlags);
142+
staticchar*pg_get_triggerdef_worker(Oidtrigid,boolpretty);
142143
staticvoiddecompile_column_index_array(Datumcolumn_index_array,OidrelId,
143144
StringInfobuf);
144145
staticchar*pg_get_ruledef_worker(Oidruleoid,intprettyFlags);
@@ -462,6 +463,22 @@ Datum
462463
pg_get_triggerdef(PG_FUNCTION_ARGS)
463464
{
464465
Oidtrigid=PG_GETARG_OID(0);
466+
467+
PG_RETURN_TEXT_P(string_to_text(pg_get_triggerdef_worker(trigid, false)));
468+
}
469+
470+
Datum
471+
pg_get_triggerdef_ext(PG_FUNCTION_ARGS)
472+
{
473+
Oidtrigid=PG_GETARG_OID(0);
474+
boolpretty=PG_GETARG_BOOL(1);
475+
476+
PG_RETURN_TEXT_P(string_to_text(pg_get_triggerdef_worker(trigid,pretty)));
477+
}
478+
479+
staticchar*
480+
pg_get_triggerdef_worker(Oidtrigid,boolpretty)
481+
{
465482
HeapTupleht_trig;
466483
Form_pg_triggertrigrec;
467484
StringInfoDatabuf;
@@ -498,9 +515,10 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
498515
initStringInfo(&buf);
499516

500517
tgname=NameStr(trigrec->tgname);
501-
appendStringInfo(&buf,"CREATE %sTRIGGER %s",
518+
appendStringInfo(&buf,"CREATE %sTRIGGER %s",
502519
trigrec->tgisconstraint ?"CONSTRAINT " :"",
503520
quote_identifier(tgname));
521+
appendStringInfoString(&buf,pretty ?"\n " :" ");
504522

505523
if (TRIGGER_FOR_BEFORE(trigrec->tgtype))
506524
appendStringInfo(&buf,"BEFORE");
@@ -533,29 +551,33 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
533551
else
534552
appendStringInfo(&buf," TRUNCATE");
535553
}
536-
appendStringInfo(&buf," ON %s",
554+
appendStringInfo(&buf," ON %s",
537555
generate_relation_name(trigrec->tgrelid,NIL));
556+
appendStringInfoString(&buf,pretty ?"\n " :" ");
538557

539558
if (trigrec->tgisconstraint)
540559
{
541560
if (trigrec->tgconstrrelid!=InvalidOid)
542-
appendStringInfo(&buf,"FROM %s ",
543-
generate_relation_name(trigrec->tgconstrrelid,
544-
NIL));
561+
{
562+
appendStringInfo(&buf,"FROM %s",
563+
generate_relation_name(trigrec->tgconstrrelid,NIL));
564+
appendStringInfoString(&buf,pretty ?"\n " :" ");
565+
}
545566
if (!trigrec->tgdeferrable)
546567
appendStringInfo(&buf,"NOT ");
547568
appendStringInfo(&buf,"DEFERRABLE INITIALLY ");
548569
if (trigrec->tginitdeferred)
549-
appendStringInfo(&buf,"DEFERRED");
570+
appendStringInfo(&buf,"DEFERRED");
550571
else
551-
appendStringInfo(&buf,"IMMEDIATE");
552-
572+
appendStringInfo(&buf,"IMMEDIATE");
573+
appendStringInfoString(&buf,pretty ?"\n " :" ");
553574
}
554575

555576
if (TRIGGER_FOR_ROW(trigrec->tgtype))
556-
appendStringInfo(&buf,"FOR EACH ROW");
577+
appendStringInfo(&buf,"FOR EACH ROW");
557578
else
558-
appendStringInfo(&buf,"FOR EACH STATEMENT ");
579+
appendStringInfo(&buf,"FOR EACH STATEMENT");
580+
appendStringInfoString(&buf,pretty ?"\n " :" ");
559581

560582
appendStringInfo(&buf,"EXECUTE PROCEDURE %s(",
561583
generate_function_name(trigrec->tgfoid,0,
@@ -594,7 +616,7 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
594616

595617
heap_close(tgrel,AccessShareLock);
596618

597-
PG_RETURN_TEXT_P(string_to_text(buf.data));
619+
returnbuf.data;
598620
}
599621

600622
/* ----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp