diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-27 20:15:04 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-27 20:15:04 +0000 |
commit | b9d803bc82954dd7278f28b7470a6d3943f80ef9 (patch) | |
tree | bf013ef35980f1de5ef7819a6add06469a3d7e7d /src | |
parent | 0407c835c81f47313058e7c41f354a57278f1311 (diff) |
Fix AfterTriggerSaveEvent to use a test and elog, not just Assert, to check
that it's called within an AfterTriggerBeginQuery/AfterTriggerEndQuery pair.
The RI cascade triggers suppress that overhead on the assumption that they
are always run non-deferred, so it's possible to violate the condition if
someone mistakenly changes pg_trigger to mark such a trigger deferred.
We don't really care about supporting that, but throwing an error instead
of crashing seems desirable. Per report from Marcelo Costa.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/trigger.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 6f5f90f9af4..2d4b356a7f4 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.177.4.6 2008/10/25 03:33:05 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.177.4.7 2009/10/27 20:15:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2946,8 +2946,15 @@ AfterTriggerSaveEvent(ResultRelInfo *relinfo, int event, bool row_trigger, ItemPointerData oldctid; ItemPointerData newctid; + /* + * Check state. We use normal tests not Asserts because it is possible + * to reach here in the wrong state given misconfigured RI triggers, + * in particular deferring a cascade action trigger. + */ if (afterTriggers == NULL) elog(ERROR, "AfterTriggerSaveEvent() called outside of transaction"); + if (afterTriggers->query_depth < 0) + elog(ERROR, "AfterTriggerSaveEvent() called outside of query"); /* * Get the CTID's of OLD and NEW |