Commit 5d1abe64 authored by Tom Lane's avatar Tom Lane

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.
parent 4e32f8cd
...@@ -1508,16 +1508,11 @@ UtilityContainsQuery(Node *parsetree) ...@@ -1508,16 +1508,11 @@ UtilityContainsQuery(Node *parsetree)
return qry; return qry;
case T_CreateTableAsStmt: case T_CreateTableAsStmt:
/* might or might not contain a Query ... */
qry = (Query *) ((CreateTableAsStmt *) parsetree)->query; qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
if (IsA(qry, Query)) Assert(IsA(qry, Query));
{ if (qry->commandType == CMD_UTILITY)
/* Recursion currently can't be necessary here */ return UtilityContainsQuery(qry->utilityStmt);
Assert(qry->commandType != CMD_UTILITY); return qry;
return qry;
}
Assert(IsA(qry, ExecuteStmt));
return NULL;
default: default:
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment