summaryrefslogtreecommitdiff
path: root/src/backend/tcop
diff options
context:
space:
mode:
authorTom Lane2012-10-19 22:33:45 +0000
committerTom Lane2012-10-19 22:33:45 +0000
commit5d1abe64e62f2bb3c1a8a4181974f0b17b8bc21d (patch)
tree8e9759c78820bae849acf4ec74903ab6d27e1157 /src/backend/tcop
parent4e32f8cd14fa6c66400e8af188bea78b22cf5f56 (diff)
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.
Diffstat (limited to 'src/backend/tcop')
-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 97376bb3ff..491bd29a1c 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1508,16 +1508,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;