File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -10700,11 +10700,29 @@ ExecuteStmt: EXECUTE name execute_param_clause
1070010700 ctas->into = $4 ;
1070110701 ctas->relkind = OBJECT_TABLE;
1070210702 ctas->is_select_into = false ;
10703+ ctas->if_not_exists = false ;
1070310704 /* cram additional flags into the IntoClause */
1070410705 $4 ->rel->relpersistence = $2 ;
1070510706 $4 ->skipData = !($9 );
1070610707 $$ = (Node *) ctas;
1070710708 }
10709+ | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
10710+ EXECUTE name execute_param_clause opt_with_data
10711+ {
10712+ CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
10713+ ExecuteStmt *n = makeNode(ExecuteStmt);
10714+ n->name = $10 ;
10715+ n->params = $11 ;
10716+ ctas->query = (Node *) n;
10717+ ctas->into = $7 ;
10718+ ctas->relkind = OBJECT_TABLE;
10719+ ctas->is_select_into = false ;
10720+ ctas->if_not_exists = true ;
10721+ /* cram additional flags into the IntoClause */
10722+ $7 ->rel->relpersistence = $2 ;
10723+ $7 ->skipData = !($12 );
10724+ $$ = (Node *) ctas;
10725+ }
1070810726 ;
1070910727
1071010728execute_param_clause : ' (' expr_list ' )' { $$ = $2 ; }
Original file line number Diff line number Diff line change @@ -261,6 +261,20 @@ ERROR: relation "as_select1" already exists
261261CREATE TABLE IF NOT EXISTS as_select1 AS SELECT * FROM pg_class WHERE relkind = 'r';
262262NOTICE: relation "as_select1" already exists, skipping
263263DROP TABLE as_select1;
264+ PREPARE select1 AS SELECT 1 as a;
265+ CREATE TABLE as_select1 AS EXECUTE select1;
266+ CREATE TABLE as_select1 AS EXECUTE select1;
267+ ERROR: relation "as_select1" already exists
268+ SELECT * FROM as_select1;
269+ a
270+ ---
271+ 1
272+ (1 row)
273+
274+ CREATE TABLE IF NOT EXISTS as_select1 AS EXECUTE select1;
275+ NOTICE: relation "as_select1" already exists, skipping
276+ DROP TABLE as_select1;
277+ DEALLOCATE select1;
264278-- create an extra wide table to test for issues related to that
265279-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
266280\set ECHO none
Original file line number Diff line number Diff line change @@ -277,6 +277,14 @@ CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind = 'r';
277277CREATE TABLE IF NOT EXISTS as_select1 AS SELECT * FROM pg_class WHERE relkind = ' r' ;
278278DROP TABLE as_select1;
279279
280+ PREPARE select1 AS SELECT 1 as a;
281+ CREATE TABLE as_select1 AS EXECUTE select1;
282+ CREATE TABLE as_select1 AS EXECUTE select1;
283+ SELECT * FROM as_select1;
284+ CREATE TABLE IF NOT EXISTS as_select1 AS EXECUTE select1;
285+ DROP TABLE as_select1;
286+ DEALLOCATE select1;
287+
280288-- create an extra wide table to test for issues related to that
281289-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
282290\set ECHO none
You can’t perform that action at this time.
0 commit comments