Skip to content

Commit ba3989c

Browse files
author
Commitfest Bot
committed
[CF 6087] v2 - CREATE TABLE LIKE INCLUDING TRIGGERS
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/6087 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CACJufxHQ8tDG09mXW=8xfEK2_h+By1zLgrFd0EcshHp-TDGiGw@mail.gmail.com Author(s): Jian He
2 parents 8ae0f6a + 7e07d3b commit ba3989c

File tree

13 files changed

+628
-144
lines changed

13 files changed

+628
-144
lines changed

doc/src/sgml/ref/create_table.sgml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class="parameter">referential_action</replaceable> ] [ ON UPDATE <replaceable cl
8888

8989
<phrase>and <replaceable class="parameter">like_option</replaceable> is:</phrase>
9090

91-
{ INCLUDING | EXCLUDING } { COMMENTS | COMPRESSION | CONSTRAINTS | DEFAULTS | GENERATED | IDENTITY | INDEXES | STATISTICS | STORAGE | ALL }
91+
{ INCLUDING | EXCLUDING } { COMMENTS | COMPRESSION | CONSTRAINTS | DEFAULTS | GENERATED | IDENTITY | INDEXES | STATISTICS | STORAGE | TRIGGERS | ALL }
9292

9393
<phrase>and <replaceable class="parameter">partition_bound_spec</replaceable> is:</phrase>
9494

@@ -672,7 +672,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
672672
<term><literal>INCLUDING COMMENTS</literal></term>
673673
<listitem>
674674
<para>
675-
Comments for the copied columns, constraints, and indexes will be
675+
Comments for the copied columns, constraints, indexes and triggers will be
676676
copied. The default behavior is to exclude comments, resulting in
677677
the copied columns and constraints in the new table having no
678678
comments.
@@ -776,6 +776,15 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
776776
</listitem>
777777
</varlistentry>
778778

779+
<varlistentry id="sql-createtable-parms-like-opt-triggers">
780+
<term><literal>INCLUDING TRIGGERS</literal></term>
781+
<listitem>
782+
<para>
783+
Any non-internal triggers on the original table will be created on the new table.
784+
</para>
785+
</listitem>
786+
</varlistentry>
787+
779788
<varlistentry id="sql-createtable-parms-like-opt-all">
780789
<term><literal>INCLUDING ALL</literal></term>
781790
<listitem>

src/backend/catalog/index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,10 +2039,12 @@ index_constraint_create(Relation heapRelation,
20392039
trigger->deferrable = true;
20402040
trigger->initdeferred = initdeferred;
20412041
trigger->constrrel = NULL;
2042+
trigger->transformed = true;
2043+
trigger->trigcomment = NULL;
20422044

20432045
(void) CreateTrigger(trigger, NULL, RelationGetRelid(heapRelation),
20442046
InvalidOid, conOid, indexRelationId, InvalidOid,
2045-
InvalidOid, NULL, true, false);
2047+
InvalidOid, true, false);
20462048
}
20472049

20482050
/*

src/backend/commands/tablecmds.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13826,10 +13826,12 @@ CreateFKCheckTrigger(Oid myRelOid, Oid refRelOid, Constraint *fkconstraint,
1382613826
fk_trigger->deferrable = fkconstraint->deferrable;
1382713827
fk_trigger->initdeferred = fkconstraint->initdeferred;
1382813828
fk_trigger->constrrel = NULL;
13829+
fk_trigger->trigcomment = NULL;
13830+
fk_trigger->transformed = true;
1382913831

1383013832
trigAddress = CreateTrigger(fk_trigger, NULL, myRelOid, refRelOid,
1383113833
constraintOid, indexOid, InvalidOid,
13832-
parentTrigOid, NULL, true, false);
13834+
parentTrigOid, true, false);
1383313835

1383413836
/* Make changes-so-far visible */
1383513837
CommandCounterIncrement();
@@ -13871,6 +13873,8 @@ createForeignKeyActionTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstr
1387113873
fk_trigger->whenClause = NULL;
1387213874
fk_trigger->transitionRels = NIL;
1387313875
fk_trigger->constrrel = NULL;
13876+
fk_trigger->trigcomment = NULL;
13877+
fk_trigger->transformed = true;
1387413878

1387513879
switch (fkconstraint->fk_del_action)
1387613880
{
@@ -13907,7 +13911,7 @@ createForeignKeyActionTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstr
1390713911

1390813912
trigAddress = CreateTrigger(fk_trigger, NULL, refRelOid, myRelOid,
1390913913
constraintOid, indexOid, InvalidOid,
13910-
parentDelTrigger, NULL, true, false);
13914+
parentDelTrigger, true, false);
1391113915
if (deleteTrigOid)
1391213916
*deleteTrigOid = trigAddress.objectId;
1391313917

@@ -13931,6 +13935,8 @@ createForeignKeyActionTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstr
1393113935
fk_trigger->whenClause = NULL;
1393213936
fk_trigger->transitionRels = NIL;
1393313937
fk_trigger->constrrel = NULL;
13938+
fk_trigger->trigcomment = NULL;
13939+
fk_trigger->transformed = true;
1393413940

1393513941
switch (fkconstraint->fk_upd_action)
1393613942
{
@@ -13967,7 +13973,7 @@ createForeignKeyActionTriggers(Oid myRelOid, Oid refRelOid, Constraint *fkconstr
1396713973

1396813974
trigAddress = CreateTrigger(fk_trigger, NULL, refRelOid, myRelOid,
1396913975
constraintOid, indexOid, InvalidOid,
13970-
parentUpdTrigger, NULL, true, false);
13976+
parentUpdTrigger, true, false);
1397113977
if (updateTrigOid)
1397213978
*updateTrigOid = trigAddress.objectId;
1397313979
}
@@ -20857,15 +20863,17 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
2085720863
trigStmt->timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK;
2085820864
trigStmt->events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK;
2085920865
trigStmt->columns = cols;
20860-
trigStmt->whenClause = NULL; /* passed separately */
20866+
trigStmt->whenClause = qual;
2086120867
trigStmt->transitionRels = NIL; /* not supported at present */
2086220868
trigStmt->deferrable = trigForm->tgdeferrable;
2086320869
trigStmt->initdeferred = trigForm->tginitdeferred;
2086420870
trigStmt->constrrel = NULL; /* passed separately */
20871+
trigStmt->trigcomment = NULL;
20872+
trigStmt->transformed = true; /* whenClause alerady transformed */
2086520873

2086620874
CreateTriggerFiringOn(trigStmt, NULL, RelationGetRelid(partition),
2086720875
trigForm->tgconstrrelid, InvalidOid, InvalidOid,
20868-
trigForm->tgfoid, trigForm->oid, qual,
20876+
trigForm->tgfoid, trigForm->oid,
2086920877
false, true, trigForm->tgenabled);
2087020878

2087120879
MemoryContextSwitchTo(oldcxt);

0 commit comments

Comments
 (0)