|
9 | 9 | * |
10 | 10 | * |
11 | 11 | * 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 $ |
13 | 13 | * |
14 | 14 | *------------------------------------------------------------------------- |
15 | 15 | */ |
@@ -139,6 +139,7 @@ static char *deparse_expression_pretty(Node *expr, List *dpcontext, |
139 | 139 | boolforceprefix,boolshowimplicit, |
140 | 140 | intprettyFlags,intstartIndent); |
141 | 141 | staticchar*pg_get_viewdef_worker(Oidviewoid,intprettyFlags); |
| 142 | +staticchar*pg_get_triggerdef_worker(Oidtrigid,boolpretty); |
142 | 143 | staticvoiddecompile_column_index_array(Datumcolumn_index_array,OidrelId, |
143 | 144 | StringInfobuf); |
144 | 145 | staticchar*pg_get_ruledef_worker(Oidruleoid,intprettyFlags); |
@@ -462,6 +463,22 @@ Datum |
462 | 463 | pg_get_triggerdef(PG_FUNCTION_ARGS) |
463 | 464 | { |
464 | 465 | 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 | +{ |
465 | 482 | HeapTupleht_trig; |
466 | 483 | Form_pg_triggertrigrec; |
467 | 484 | StringInfoDatabuf; |
@@ -498,9 +515,10 @@ pg_get_triggerdef(PG_FUNCTION_ARGS) |
498 | 515 | initStringInfo(&buf); |
499 | 516 |
|
500 | 517 | tgname=NameStr(trigrec->tgname); |
501 | | -appendStringInfo(&buf,"CREATE %sTRIGGER %s", |
| 518 | +appendStringInfo(&buf,"CREATE %sTRIGGER %s", |
502 | 519 | trigrec->tgisconstraint ?"CONSTRAINT " :"", |
503 | 520 | quote_identifier(tgname)); |
| 521 | +appendStringInfoString(&buf,pretty ?"\n " :" "); |
504 | 522 |
|
505 | 523 | if (TRIGGER_FOR_BEFORE(trigrec->tgtype)) |
506 | 524 | appendStringInfo(&buf,"BEFORE"); |
@@ -533,29 +551,33 @@ pg_get_triggerdef(PG_FUNCTION_ARGS) |
533 | 551 | else |
534 | 552 | appendStringInfo(&buf," TRUNCATE"); |
535 | 553 | } |
536 | | -appendStringInfo(&buf," ON %s", |
| 554 | +appendStringInfo(&buf," ON %s", |
537 | 555 | generate_relation_name(trigrec->tgrelid,NIL)); |
| 556 | +appendStringInfoString(&buf,pretty ?"\n " :" "); |
538 | 557 |
|
539 | 558 | if (trigrec->tgisconstraint) |
540 | 559 | { |
541 | 560 | 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 | +} |
545 | 566 | if (!trigrec->tgdeferrable) |
546 | 567 | appendStringInfo(&buf,"NOT "); |
547 | 568 | appendStringInfo(&buf,"DEFERRABLE INITIALLY "); |
548 | 569 | if (trigrec->tginitdeferred) |
549 | | -appendStringInfo(&buf,"DEFERRED"); |
| 570 | +appendStringInfo(&buf,"DEFERRED"); |
550 | 571 | else |
551 | | -appendStringInfo(&buf,"IMMEDIATE"); |
552 | | - |
| 572 | +appendStringInfo(&buf,"IMMEDIATE"); |
| 573 | +appendStringInfoString(&buf,pretty ?"\n " :" "); |
553 | 574 | } |
554 | 575 |
|
555 | 576 | if (TRIGGER_FOR_ROW(trigrec->tgtype)) |
556 | | -appendStringInfo(&buf,"FOR EACH ROW"); |
| 577 | +appendStringInfo(&buf,"FOR EACH ROW"); |
557 | 578 | else |
558 | | -appendStringInfo(&buf,"FOR EACH STATEMENT "); |
| 579 | +appendStringInfo(&buf,"FOR EACH STATEMENT"); |
| 580 | +appendStringInfoString(&buf,pretty ?"\n " :" "); |
559 | 581 |
|
560 | 582 | appendStringInfo(&buf,"EXECUTE PROCEDURE %s(", |
561 | 583 | generate_function_name(trigrec->tgfoid,0, |
@@ -594,7 +616,7 @@ pg_get_triggerdef(PG_FUNCTION_ARGS) |
594 | 616 |
|
595 | 617 | heap_close(tgrel,AccessShareLock); |
596 | 618 |
|
597 | | -PG_RETURN_TEXT_P(string_to_text(buf.data)); |
| 619 | +returnbuf.data; |
598 | 620 | } |
599 | 621 |
|
600 | 622 | /* ---------- |
|