File tree 3 files changed +25
-11
lines changed
3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -3834,7 +3834,7 @@ ExistingIndex: USING INDEX index_name { $$ = $3; }
3834
3834
/* ****************************************************************************
3835
3835
*
3836
3836
* QUERY :
3837
- * CREATE STATISTICS stats_name [(stat types)]
3837
+ * CREATE STATISTICS [IF NOT EXISTS] stats_name [(stat types)]
3838
3838
* ON expression-list FROM from_list
3839
3839
*
3840
3840
* Note: the expectation here is that the clauses after ON are a subset of
@@ -3846,15 +3846,26 @@ ExistingIndex: USING INDEX index_name { $$ = $3; }
3846
3846
*****************************************************************************/
3847
3847
3848
3848
CreateStatsStmt :
3849
- CREATE opt_if_not_exists STATISTICS any_name
3849
+ CREATE STATISTICS any_name
3850
3850
opt_name_list ON expr_list FROM from_list
3851
3851
{
3852
3852
CreateStatsStmt *n = makeNode(CreateStatsStmt);
3853
- n->defnames = $4 ;
3854
- n->stat_types = $5 ;
3855
- n->exprs = $7 ;
3856
- n->relations = $9 ;
3857
- n->if_not_exists = $2 ;
3853
+ n->defnames = $3 ;
3854
+ n->stat_types = $4 ;
3855
+ n->exprs = $6 ;
3856
+ n->relations = $8 ;
3857
+ n->if_not_exists = false ;
3858
+ $$ = (Node *)n;
3859
+ }
3860
+ | CREATE STATISTICS IF_P NOT EXISTS any_name
3861
+ opt_name_list ON expr_list FROM from_list
3862
+ {
3863
+ CreateStatsStmt *n = makeNode(CreateStatsStmt);
3864
+ n->defnames = $6 ;
3865
+ n->stat_types = $7 ;
3866
+ n->exprs = $9 ;
3867
+ n->relations = $11 ;
3868
+ n->if_not_exists = true ;
3858
3869
$$ = (Node *)n;
3859
3870
}
3860
3871
;
Original file line number Diff line number Diff line change @@ -30,9 +30,11 @@ CREATE STATISTICS tst ON (relpages, reltuples) FROM pg_class;
30
30
ERROR: only simple column references are allowed in CREATE STATISTICS
31
31
CREATE STATISTICS tst (unrecognized) ON relname, relnatts FROM pg_class;
32
32
ERROR: unrecognized statistic type "unrecognized"
33
- -- Ensure stats are dropped sanely
33
+ -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
34
34
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
35
- CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
35
+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
36
+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
37
+ NOTICE: statistics object "ab1_a_b_stats" already exists, skipping
36
38
DROP STATISTICS ab1_a_b_stats;
37
39
CREATE SCHEMA regress_schema_2;
38
40
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON a, b FROM ab1;
Original file line number Diff line number Diff line change @@ -18,9 +18,10 @@ CREATE STATISTICS tst ON relnatts + relpages FROM pg_class;
18
18
CREATE STATISTICS tst ON (relpages, reltuples) FROM pg_class;
19
19
CREATE STATISTICS tst (unrecognized) ON relname, relnatts FROM pg_class;
20
20
21
- -- Ensure stats are dropped sanely
21
+ -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
22
22
CREATE TABLE ab1 (a INTEGER , b INTEGER , c INTEGER );
23
- CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
23
+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
24
+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
24
25
DROP STATISTICS ab1_a_b_stats;
25
26
26
27
CREATE SCHEMA regress_schema_2 ;
You can’t perform that action at this time.
0 commit comments