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 @@ -10383,11 +10383,29 @@ ExecuteStmt: EXECUTE name execute_param_clause
10383
10383
ctas->into = $4 ;
10384
10384
ctas->relkind = OBJECT_TABLE;
10385
10385
ctas->is_select_into = false ;
10386
+ ctas->if_not_exists = false ;
10386
10387
/* cram additional flags into the IntoClause */
10387
10388
$4 ->rel->relpersistence = $2 ;
10388
10389
$4 ->skipData = !($9 );
10389
10390
$$ = (Node *) ctas;
10390
10391
}
10392
+ | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
10393
+ EXECUTE name execute_param_clause opt_with_data
10394
+ {
10395
+ CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
10396
+ ExecuteStmt *n = makeNode(ExecuteStmt);
10397
+ n->name = $10 ;
10398
+ n->params = $11 ;
10399
+ ctas->query = (Node *) n;
10400
+ ctas->into = $7 ;
10401
+ ctas->relkind = OBJECT_TABLE;
10402
+ ctas->is_select_into = false ;
10403
+ ctas->if_not_exists = true ;
10404
+ /* cram additional flags into the IntoClause */
10405
+ $7 ->rel->relpersistence = $2 ;
10406
+ $7 ->skipData = !($12 );
10407
+ $$ = (Node *) ctas;
10408
+ }
10391
10409
;
10392
10410
10393
10411
execute_param_clause : ' (' expr_list ' )' { $$ = $2 ; }
Original file line number Diff line number Diff line change @@ -258,6 +258,20 @@ ERROR: relation "as_select1" already exists
258
258
CREATE TABLE IF NOT EXISTS as_select1 AS SELECT * FROM pg_class WHERE relkind = 'r';
259
259
NOTICE: relation "as_select1" already exists, skipping
260
260
DROP TABLE as_select1;
261
+ PREPARE select1 AS SELECT 1 as a;
262
+ CREATE TABLE as_select1 AS EXECUTE select1;
263
+ CREATE TABLE as_select1 AS EXECUTE select1;
264
+ ERROR: relation "as_select1" already exists
265
+ SELECT * FROM as_select1;
266
+ a
267
+ ---
268
+ 1
269
+ (1 row)
270
+
271
+ CREATE TABLE IF NOT EXISTS as_select1 AS EXECUTE select1;
272
+ NOTICE: relation "as_select1" already exists, skipping
273
+ DROP TABLE as_select1;
274
+ DEALLOCATE select1;
261
275
-- check that the oid column is added before the primary key is checked
262
276
CREATE TABLE oid_pk (f1 INT, PRIMARY KEY(oid)) WITH OIDS;
263
277
DROP TABLE oid_pk;
Original file line number Diff line number Diff line change @@ -274,6 +274,14 @@ CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind = 'r';
274
274
CREATE TABLE IF NOT EXISTS as_select1 AS SELECT * FROM pg_class WHERE relkind = ' r' ;
275
275
DROP TABLE as_select1;
276
276
277
+ PREPARE select1 AS SELECT 1 as a;
278
+ CREATE TABLE as_select1 AS EXECUTE select1;
279
+ CREATE TABLE as_select1 AS EXECUTE select1;
280
+ SELECT * FROM as_select1;
281
+ CREATE TABLE IF NOT EXISTS as_select1 AS EXECUTE select1;
282
+ DROP TABLE as_select1;
283
+ DEALLOCATE select1;
284
+
277
285
-- check that the oid column is added before the primary key is checked
278
286
CREATE TABLE oid_pk (f1 INT , PRIMARY KEY (oid )) WITH OIDS;
279
287
DROP TABLE oid_pk;
You can’t perform that action at this time.
0 commit comments