summaryrefslogtreecommitdiff
path: root/src/backend/executor/spi.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-08-11 11:22:25 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-08-11 11:22:25 -0400
commit268d92e5336d25b296a5ccf8ccf803a2adb40251 (patch)
tree943b7398707b7fb09131ae6a6915f14cd6e58645 /src/backend/executor/spi.c
parent042b6beeeb17ec34ea0764921574f2d8a2761472 (diff)
Fix busted Assert for CREATE MATVIEW ... WITH NO DATA.
Commit 874fe3aea changed the command tag returned for CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA, but missed that there was code in spi.c that expected the command tag to always be "SELECT". Fortunately, the consequence was only an Assert failure, so this oversight should have no impact in production builds. Since this code path was evidently un-exercised, add a regression test. Per report from Shivam Saxena. Back-patch to 9.3, like the previous commit. Michael Paquier Report: <97218716-480B-4527-B5CD-D08D798A0C7B@dresources.com>
Diffstat (limited to 'src/backend/executor/spi.c')
-rw-r--r--src/backend/executor/spi.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 649040e8fd7..82d5005e872 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -2186,15 +2186,23 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
*/
if (IsA(stmt, CreateTableAsStmt))
{
- Assert(strncmp(completionTag, "SELECT ", 7) == 0);
- _SPI_current->processed = strtoul(completionTag + 7,
- NULL, 10);
+ CreateTableAsStmt *ctastmt = (CreateTableAsStmt *) stmt;
+
+ if (strncmp(completionTag, "SELECT ", 7) == 0)
+ _SPI_current->processed =
+ strtoul(completionTag + 7, NULL, 10);
+ else
+ {
+ /* Must be a CREATE ... WITH NO DATA */
+ Assert(ctastmt->into->skipData);
+ _SPI_current->processed = 0;
+ }
/*
* For historical reasons, if CREATE TABLE AS was spelled
* as SELECT INTO, return a special return code.
*/
- if (((CreateTableAsStmt *) stmt)->is_select_into)
+ if (ctastmt->is_select_into)
res = SPI_OK_SELINTO;
}
else if (IsA(stmt, CopyStmt))