SPI_cursor_open failed to enforce that only read-only queries could be
authorTom Lane <[email protected]>
Sat, 17 Mar 2007 03:15:55 +0000 (03:15 +0000)
committerTom Lane <[email protected]>
Sat, 17 Mar 2007 03:15:55 +0000 (03:15 +0000)
executed in read_only mode.  This could lead to various relatively-subtle
failures, such as an allegedly stable function returning non-stable results.
Bug goes all the way back to the introduction of read-only mode in 8.0.
Per report from Gaetano Mendola.

src/backend/executor/spi.c

index 11e092302aa1145620aeaa46b855700dd083e017..6645cd2f16b1ff950b935530c4d354dd5df21696 100644 (file)
@@ -860,6 +860,16 @@ SPI_cursor_open(const char *name, void *plan,
                        break;
        }
 
+       /*
+        * If told to be read-only, we'd better check for read-only queries.
+        */
+       if (read_only && !QueryIsReadOnly(queryTree))
+               ereport(ERROR,
+                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                /* translator: %s is a SQL statement name */
+                                errmsg("%s is not allowed in a non-volatile function",
+                                               CreateQueryTag(queryTree))));
+
        /* Reset SPI result (note we deliberately don't touch lastoid) */
        SPI_processed = 0;
        SPI_tuptable = NULL;