aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-04-11 20:07:17 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-04-11 20:07:17 -0400
commit079013f0b7e35f2fb14cdbe2667a1d9aac4f770e (patch)
tree9e550027535441b6cb657d1c84d277b07b58f083 /src/backend/executor
parent8207c6baf8b42085bef442178ce8721ea726d9c7 (diff)
downloadpostgresql-079013f0b7e35f2fb14cdbe2667a1d9aac4f770e.tar.gz
postgresql-079013f0b7e35f2fb14cdbe2667a1d9aac4f770e.zip
Fix _SPI_execute_plan() for CREATE TABLE IF NOT EXISTS foo AS ...
When IF NOT EXISTS was added to CREATE TABLE AS, this logic didn't get the memo, possibly resulting in an Assert failure. It looks like there would have been no ill effects in a non-Assert build, though. Back-patch to 9.5 where the IF NOT EXISTS option was added. Stas Kelvich
Diffstat (limited to 'src/backend/executor')
-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 300401e01f9..dc039f41748 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -2217,15 +2217,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 an IF NOT EXISTS that did nothing */
+ Assert(ctastmt->if_not_exists);
+ _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))