Reject SQL functions containing utility statements
authorTomas Vondra <[email protected]>
Sun, 30 Jul 2017 16:17:27 +0000 (18:17 +0200)
committerTomas Vondra <[email protected]>
Mon, 31 Jul 2017 01:21:29 +0000 (03:21 +0200)
The check was not effective for the same reason as 5a54abb7acd, that is
not accounting for XL wrapping the original command into RawStmt. Fix
that by checking parsetree->stmt, and also add an assert checking we
actually got a RawStmt in the first place.

src/backend/catalog/pg_proc.c

index 3ba00c34cae8983366fea4c78c8f592d1a325249..088111f0d5aa74b7a96ccd93dcd0ec640cf970dd 100644 (file)
@@ -937,9 +937,11 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
                                RawStmt    *parsetree = lfirst_node(RawStmt, lc);
                                List       *querytree_sublist;
 
+                               Assert(IsA(parsetree, RawStmt));
+
 #ifdef PGXC
                                /* Block CTAS in SQL functions */
-                               if (IsA(parsetree, CreateTableAsStmt))
+                               if (IsA(parsetree->stmt, CreateTableAsStmt))
                                        ereport(ERROR,
                                                        (errcode(ERRCODE_SYNTAX_ERROR),
                                                        errmsg("In XC, SQL functions cannot contain utility statements")));