]> granicus.if.org Git - postgresql/commitdiff
Fix UtilityContainsQuery() to handle CREATE TABLE AS EXECUTE correctly.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Oct 2012 22:33:53 +0000 (18:33 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Oct 2012 22:33:53 +0000 (18:33 -0400)
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.

src/backend/tcop/utility.c

index 3b0ebdd3e7590da84d5af2ac9b6ab9b296750f22..509bf4d3d81286fdabcb70855836093a3b1e1cd6 100644 (file)
@@ -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;