1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Provide the OR REPLACE option for CREATE TRIGGER.

This is mostly straightforward.  However, we disallow replacing
constraint triggers or changing the is-constraint property; perhaps
that can be added later, but the complexity versus benefit tradeoff
doesn't look very good.

Also, no special thought is taken here for whether replacing an
existing trigger should result in changes to queued-but-not-fired
trigger actions.  We just document that if you're surprised by the
results, too bad, don't do that.  (Note that any such pending trigger
activity would have to be within the current session.)

Takamichi Osumi, reviewed at various times by Surafel Temesgen,
Peter Smith, and myself

Discussion: https://postgr.es/m/0DDF369B45A1B44B8A687ED43F06557C010BC362@G01JPEXMBYT03
This commit is contained in:
Tom Lane
2020-11-14 17:05:34 -05:00
parent dbca94510c
commit 92bf7e2d02
10 changed files with 408 additions and 114 deletions

View File

@ -5218,48 +5218,54 @@ am_type:
*****************************************************************************/
CreateTrigStmt:
CREATE TRIGGER name TriggerActionTime TriggerEvents ON
CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
qualified_name TriggerReferencing TriggerForSpec TriggerWhen
EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
{
CreateTrigStmt *n = makeNode(CreateTrigStmt);
n->trigname = $3;
n->relation = $7;
n->funcname = $13;
n->args = $15;
n->row = $9;
n->timing = $4;
n->events = intVal(linitial($5));
n->columns = (List *) lsecond($5);
n->whenClause = $10;
n->transitionRels = $8;
n->isconstraint = false;
n->replace = $2;
n->isconstraint = false;
n->trigname = $4;
n->relation = $8;
n->funcname = $14;
n->args = $16;
n->row = $10;
n->timing = $5;
n->events = intVal(linitial($6));
n->columns = (List *) lsecond($6);
n->whenClause = $11;
n->transitionRels = $9;
n->deferrable = false;
n->initdeferred = false;
n->constrrel = NULL;
$$ = (Node *)n;
}
| CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
| CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
qualified_name OptConstrFromTable ConstraintAttributeSpec
FOR EACH ROW TriggerWhen
EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
{
CreateTrigStmt *n = makeNode(CreateTrigStmt);
n->trigname = $4;
n->relation = $8;
n->funcname = $17;
n->args = $19;
n->replace = $2;
if (n->replace) /* not supported, see CreateTrigger */
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported")));
n->isconstraint = true;
n->trigname = $5;
n->relation = $9;
n->funcname = $18;
n->args = $20;
n->row = true;
n->timing = TRIGGER_TYPE_AFTER;
n->events = intVal(linitial($6));
n->columns = (List *) lsecond($6);
n->whenClause = $14;
n->events = intVal(linitial($7));
n->columns = (List *) lsecond($7);
n->whenClause = $15;
n->transitionRels = NIL;
n->isconstraint = true;
processCASbits($10, @10, "TRIGGER",
processCASbits($11, @11, "TRIGGER",
&n->deferrable, &n->initdeferred, NULL,
NULL, yyscanner);
n->constrrel = $9;
n->constrrel = $10;
$$ = (Node *)n;
}
;