aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-19 18:33:53 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-19 18:33:53 -0400
commit12b721a7f0e3cb05630f267e0d9b4e63bbba6b0b (patch)
tree41f3d6ba5113c448dcf275e6d61855684ba3d029
parent8a3249f12447468c4ac5a3b91cfdad5573e2b660 (diff)
downloadpostgresql-12b721a7f0e3cb05630f267e0d9b4e63bbba6b0b.tar.gz
postgresql-12b721a7f0e3cb05630f267e0d9b4e63bbba6b0b.zip
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.
-rw-r--r--src/backend/tcop/utility.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 3b0ebdd3e75..509bf4d3d81 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1365,16 +1365,11 @@ UtilityContainsQuery(Node *parsetree)
return qry;
case T_CreateTableAsStmt:
- /* might or might not contain a Query ... */
qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
- if (IsA(qry, Query))
- {
- /* Recursion currently can't be necessary here */
- Assert(qry->commandType != CMD_UTILITY);
- return qry;
- }
- Assert(IsA(qry, ExecuteStmt));
- return NULL;
+ Assert(IsA(qry, Query));
+ if (qry->commandType == CMD_UTILITY)
+ return UtilityContainsQuery(qry->utilityStmt);
+ return qry;
default:
return NULL;