*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.107 2006/10/04 00:29:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.108 2006/10/12 17:02:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* Utility commands don't need Executor. */
if (es->qd->operation != CMD_UTILITY)
{
- AfterTriggerBeginQuery();
+ /*
+ * Only set up to collect queued triggers if it's not a SELECT.
+ * This isn't just an optimization, but is necessary in case a SELECT
+ * returns multiple rows to caller --- we mustn't exit from the
+ * function execution with a stacked AfterTrigger level still active.
+ */
+ if (es->qd->operation != CMD_SELECT)
+ AfterTriggerBeginQuery();
ExecutorStart(es->qd, 0);
}
{
ActiveSnapshot = es->qd->snapshot;
- AfterTriggerEndQuery(es->qd->estate);
+ if (es->qd->operation != CMD_SELECT)
+ AfterTriggerEndQuery(es->qd->estate);
ExecutorEnd(es->qd);
}
PG_CATCH();