[Please CC any replies]

Hi,

As per discussion on -hackers, type input functions can be called prior
to there being a current snapshot, causing any queries you execute to
fail with the "no snapshot has been set" error. So I propose to simply
have SPI_connect fail right off the bat and document that to avoid
future surprises. At least until the issue of non-immutable type input
functions has been sorted out.

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Index: src/backend/executor/spi.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/executor/spi.c,v
retrieving revision 1.131
diff -u -r1.131 spi.c
--- src/backend/executor/spi.c  13 Oct 2004 01:25:10 -0000      1.131
+++ src/backend/executor/spi.c  13 Aug 2005 19:50:40 -0000
@@ -70,6 +70,12 @@
         */
        if (_SPI_curid != _SPI_connected)
                return SPI_ERROR_CONNECT;
+               
+       /* You can't actually execute queries if there is no current
+        * snapshot, so return an error straightaway. eg User defined type
+        * input functions */
+       if (SerializableSnapshot == NULL)
+               return SPI_ERROR_CONNECT;
 
        if (_SPI_stack == NULL)
        {
Index: doc/src/sgml/spi.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/spi.sgml,v
retrieving revision 1.42
diff -u -r1.42 spi.sgml
--- doc/src/sgml/spi.sgml       29 Jul 2005 13:00:03 -0000      1.42
+++ doc/src/sgml/spi.sgml       13 Aug 2005 19:50:40 -0000
@@ -106,6 +106,13 @@
    <function>SPI_finish</function> are forbidden.
    (But see <function>SPI_push</function> and <function>SPI_pop</function>.)
   </para>
+
+  <para> 
+   <function>SPI_connect</function> will also fail if there is no current
+   snapshot. This generally only happens in implicitly called functions such
+   as type input functions.
+  </para>
+
  </refsect1>
 
  <refsect1>

Attachment: pgp3aK3nTsDsV.pgp
Description: PGP signature

Reply via email to