From c23bd9232fb1d757ec8d422422232d789556860a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 7 Jan 2009 20:39:15 +0000 Subject: Insert conditional SPI_push/SPI_pop calls into InputFunctionCall, OutputFunctionCall, and friends. This allows SPI-using functions to invoke datatype I/O without concern for the possibility that a SPI-using function will be called (which could be either the I/O function itself, or a function used in a domain check constraint). It's a tad ugly, but not nearly as ugly as what'd be needed to make this work via retail insertion of push/pop operations in all the PLs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts my patch of 2007-01-30 that inserted some retail SPI_push/pop calls into plpgsql; that approach only fixed plpgsql, and not any other PLs. But the other PLs have the issue too, as illustrated by a recent gripe from Christian Schröder. Back-patch to 8.2, which is as far back as this solution will work. It's also as far back as we need to worry about the domain-constraint case, since earlier versions did not attempt to check domain constraints within datatype input. I'm not aware of any old I/O functions that use SPI themselves, so this should be sufficient for a back-patch. --- src/backend/executor/spi.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/backend/executor/spi.c') diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 3515ee6e0b1..171776aa82a 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.165.2.5 2008/10/16 13:23:34 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.165.2.6 2009/01/07 20:39:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -284,6 +284,31 @@ SPI_pop(void) _SPI_curid--; } +/* Conditional push: push only if we're inside a SPI procedure */ +bool +SPI_push_conditional(void) +{ + bool pushed = (_SPI_curid != _SPI_connected); + + if (pushed) + { + _SPI_curid++; + /* We should now be in a state where SPI_connect would succeed */ + Assert(_SPI_curid == _SPI_connected); + } + return pushed; +} + +/* Conditional pop: pop only if SPI_push_conditional pushed */ +void +SPI_pop_conditional(bool pushed) +{ + /* We should be in a state where SPI_connect would succeed */ + Assert(_SPI_curid == _SPI_connected); + if (pushed) + _SPI_curid--; +} + /* Restore state of SPI stack after aborting a subtransaction */ void SPI_restore_connection(void) -- cgit v1.2.3