'Create table if not exists as' breaks SPI_execute
Hi.
SPI_execute assumes that CreateTableAsStmt always have completionTag == “completionTag”.
But it isn’t true in case of ‘IF NOT EXISTS’ present.
Attachments:
spi-cta.patchapplication/octet-stream; name=spi-cta.patchDownload
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index fd94179..49ebce4 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -2217,15 +2217,21 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
*/
if (IsA(stmt, CreateTableAsStmt))
{
- Assert(strncmp(completionTag, "SELECT ", 7) == 0);
- _SPI_current->processed = pg_strtouint64(completionTag + 7,
+ CreateTableAsStmt *ctastmt = (CreateTableAsStmt *) stmt;
+
+ if (strncmp(completionTag, "SELECT ", 7) == 0)
+ _SPI_current->processed = pg_strtouint64(completionTag + 7,
NULL, 10);
+ else if (*completionTag == '\0' && ctastmt->if_not_exists)
+ _SPI_current->processed = 0;
+ else
+ Assert(false);
/*
* 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))
On 11 Apr 2016, at 18:41, Stas Kelvich <s.kelvich@postgrespro.ru> wrote:
Hi.
SPI_execute assumes that CreateTableAsStmt always have completionTag == “completionTag”.
But it isn’t true in case of ‘IF NOT EXISTS’ present.<spi-cta.patch>
Sorry, I meant completionTag == “SELECT”.
--
Stas Kelvich
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Stas Kelvich <s.kelvich@postgrespro.ru> writes:
SPI_execute assumes that CreateTableAsStmt always have completionTag == “completionTag”.
But it isn’t true in case of ‘IF NOT EXISTS’ present.
Pushed, thanks.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers