From: Tom Lane Date: Wed, 30 May 2007 21:01:53 +0000 (+0000) Subject: Fix overly-strict sanity check in BeginInternalSubTransaction that made it X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=75762d20767de279d1dda09aa019fa29ac1dbe8e;p=users%2Fbernd%2Fpostgres.git Fix overly-strict sanity check in BeginInternalSubTransaction that made it fail when used in a deferred trigger. Bug goes back to 8.0; no doubt the reason it hadn't been noticed is that we've been discouraging use of user-defined constraint triggers. Per report from Frank van Vugt. --- diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index fe212c457a..cc8d70e978 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3253,10 +3253,11 @@ RollbackToSavepoint(List *options) /* * BeginInternalSubTransaction - * This is the same as DefineSavepoint except it allows TBLOCK_STARTED - * state, and therefore it can safely be used in a function that might - * be called when not inside a BEGIN block. Also, we automatically - * cycle through CommitTransactionCommand/StartTransactionCommand + * This is the same as DefineSavepoint except it allows TBLOCK_STARTED, + * TBLOCK_END, and TBLOCK_PREPARE states, and therefore it can safely be + * used in functions that might be called when not inside a BEGIN block + * or when running deferred triggers at COMMIT/PREPARE time. Also, it + * automatically does CommitTransactionCommand/StartTransactionCommand * instead of expecting the caller to do it. */ void @@ -3268,6 +3269,8 @@ BeginInternalSubTransaction(char *name) { case TBLOCK_STARTED: case TBLOCK_INPROGRESS: + case TBLOCK_END: + case TBLOCK_PREPARE: case TBLOCK_SUBINPROGRESS: /* Normal subtransaction start */ PushTransaction(); @@ -3285,7 +3288,6 @@ BeginInternalSubTransaction(char *name) case TBLOCK_DEFAULT: case TBLOCK_BEGIN: case TBLOCK_SUBBEGIN: - case TBLOCK_END: case TBLOCK_SUBEND: case TBLOCK_ABORT: case TBLOCK_SUBABORT: @@ -3295,7 +3297,6 @@ BeginInternalSubTransaction(char *name) case TBLOCK_SUBABORT_PENDING: case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: - case TBLOCK_PREPARE: elog(FATAL, "BeginInternalSubTransaction: unexpected state %s", BlockStateAsString(s->blockState)); break;