aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorDean Rasheed <dean.a.rasheed@gmail.com>2022-07-21 19:23:13 +0100
committerDean Rasheed <dean.a.rasheed@gmail.com>2022-07-21 19:23:13 +0100
commit624aa2a13bd02dd584bb0995c883b5b93b2152df (patch)
tree9fb20bf9030cd894df4dcf55665a5b51fb0f85b4 /src/backend/parser
parentfa6c230ef23cfe5367cb883fd461580f6a42619d (diff)
downloadpostgresql-624aa2a13bd02dd584bb0995c883b5b93b2152df.tar.gz
postgresql-624aa2a13bd02dd584bb0995c883b5b93b2152df.zip
Make the name optional in CREATE STATISTICS.
This allows users to omit the statistics name in a CREATE STATISTICS command, letting the system auto-generate a sensible, unique name, putting the statistics object in the same schema as the table. Simon Riggs, reviewed by Matthias van de Meent. Discussion: https://postgr.es/m/CANbhV-FGD2d_C3zFTfT2aRfX_TaPSgOeKES58RLZx5XzQp5NhA@mail.gmail.com
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index d649a1b8d13..0a874a04aa1 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -434,7 +434,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
old_aggr_definition old_aggr_list
oper_argtypes RuleActionList RuleActionMulti
opt_column_list columnList opt_name_list
- sort_clause opt_sort_clause sortby_list index_params stats_params
+ sort_clause opt_sort_clause sortby_list index_params
+ opt_stats_name stats_params
opt_include opt_c_include index_including_params
name_list role_list from_clause from_list opt_array_bounds
qualified_name_list any_name any_name_list type_name_list
@@ -4533,7 +4534,7 @@ ExistingIndex: USING INDEX name { $$ = $3; }
/*****************************************************************************
*
* QUERY :
- * CREATE STATISTICS [IF NOT EXISTS] stats_name [(stat types)]
+ * CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
* ON expression-list FROM from_list
*
* Note: the expectation here is that the clauses after ON are a subset of
@@ -4545,7 +4546,7 @@ ExistingIndex: USING INDEX name { $$ = $3; }
*****************************************************************************/
CreateStatsStmt:
- CREATE STATISTICS any_name
+ CREATE STATISTICS opt_stats_name
opt_name_list ON stats_params FROM from_list
{
CreateStatsStmt *n = makeNode(CreateStatsStmt);
@@ -4573,6 +4574,12 @@ CreateStatsStmt:
}
;
+/* Statistics name is optional unless IF NOT EXISTS is specified */
+opt_stats_name:
+ any_name { $$ = $1; }
+ | /*EMPTY*/ { $$ = NULL; }
+ ;
+
/*
* Statistics attributes can be either simple column references, or arbitrary
* expressions in parens. For compatibility with index attributes permitted