8000 Fix UtilityContainsQuery() to handle CREATE TABLE AS EXECUTE correctly. · danielcode/postgres@12b721a · GitHub
[go: up one dir, main page]

Skip to content

Commit 12b721a

Browse files
committed
Fix UtilityContainsQuery() to handle CREATE TABLE AS EXECUTE correctly.
The code seems to have been written to handle the pre-parse-analysis representation, where an ExecuteStmt would appear directly under CreateTableAsStmt. But in reality the function is only run on already-parse-analyzed statements, so there will be a Query node in between. We'd not noticed the bug because the function is generally not used at all except in extended query protocol. Per report from Robert Haas and Rushabh Lathia.
1 parent 8a3249f commit 12b721a

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/backend/tcop/utility.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,16 +1365,11 @@ UtilityContainsQuery(Node *parsetree)
13651365
return qry;
13661366

13671367
case T_CreateTableAsStmt:
1368-
/* might or might not contain a Query ... */
13691368
8F70 qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
1370-
if (IsA(qry, Query))
1371-
{
1372-
/* Recursion currently can't be necessary here */
1373-
Assert(qry->commandType != CMD_UTILITY);
1374-
return qry;
1375-
}
1376-
Assert(IsA(qry, ExecuteStmt));
1377-
return NULL;
1369+
Assert(IsA(qry, Query));
1370+
if (qry->commandType == CMD_UTILITY)
1371+
return UtilityContainsQuery(qry->utilityStmt);
1372+
return qry;
13781373

13791374
default:
13801375
return NULL;

0 commit comments

Comments
 (0)
0