@@ -401,7 +401,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
401401%type <node> columnDef columnOptions
402402%type <defelt> def_elem reloption_elem old_aggr_elem
403403%type <node> def_arg columnElem where_clause where_or_current_clause
404- a_expr b_expr c_expr func_expr AexprConst indirection_el
404+ a_expr b_expr c_expr AexprConst indirection_el
405405columnref in_expr having_clause func_table array_expr
406406ExclusionWhereClause
407407%type <list> ExclusionConstraintList ExclusionConstraintElem
@@ -481,6 +481,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
481481%type <ival> document_or_content
482482%type <boolean> xml_whitespace_option
483483
484+ %type <node> func_application func_expr_common_subexpr
485+ %type <node> func_expr func_expr_windowless
484486%type <node> common_table_expr
485487%type <with> with_clause opt_with_clause
486488%type <list> cte_list
@@ -6132,7 +6134,7 @@ index_elem:ColId opt_collate opt_class opt_asc_desc opt_nulls_order
61326134$$ ->ordering =$4 ;
61336135$$ ->nulls_ordering =$5 ;
61346136}
6135- | func_expr opt_collate opt_class opt_asc_desc opt_nulls_order
6137+ | func_expr_windowless opt_collate opt_class opt_asc_desc opt_nulls_order
61366138{
61376139$$ = makeNode(IndexElem);
61386140$$ ->name =NULL ;
@@ -9894,8 +9896,7 @@ relation_expr_opt_alias: relation_expr%prec UMINUS
98949896}
98959897;
98969898
9897-
9898- func_table :func_expr {$$ =$1 ; }
9899+ func_table :func_expr_windowless {$$ =$1 ; }
98999900;
99009901
99019902
@@ -11079,15 +11080,7 @@ c_expr:columnref{ $$ = $1; }
1107911080}
1108011081;
1108111082
11082- /*
11083- * func_expr is split out from c_expr just so that we have a classification
11084- * for "everything that is a function call or looks like one". This isn't
11085- * very important, but it saves us having to document which variants are
11086- * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
11087- * (Note that many of the special SQL functions wouldn't actually make any
11088- * sense as functional index entries, but we ignore that consideration here.)
11089- */
11090- func_expr:func_name' (' ' )' over_clause
11083+ func_application: func_name' (' ' )'
1109111084{
1109211085FuncCall *n =makeNode (FuncCall);
1109311086n->funcname = $1 ;
@@ -11096,11 +11089,11 @@ func_expr:func_name '(' ')' over_clause
1109611089n->agg_star =FALSE ;
1109711090n->agg_distinct =FALSE ;
1109811091n->func_variadic =FALSE ;
11099- n->over =$ 4 ;
11092+ n->over =NULL ;
1110011093n->location = @1 ;
1110111094$$ = (Node *)n;
1110211095}
11103- | func_name' (' func_arg_list' )' over_clause
11096+ | func_name' (' func_arg_list' )'
1110411097{
1110511098FuncCall *n =makeNode (FuncCall);
1110611099n->funcname = $1 ;
@@ -11109,11 +11102,11 @@ func_expr:func_name '(' ')' over_clause
1110911102n->agg_star =FALSE ;
1111011103n->agg_distinct =FALSE ;
1111111104n->func_variadic =FALSE ;
11112- n->over =$ 5 ;
11105+ n->over =NULL ;
1111311106n->location = @1 ;
1111411107$$ = (Node *)n;
1111511108}
11116- | func_name' (' VARIADIC func_arg_expr' )' over_clause
11109+ | func_name' (' VARIADIC func_arg_expr' )'
1111711110{
1111811111FuncCall *n =makeNode (FuncCall);
1111911112n->funcname = $1 ;
@@ -11122,11 +11115,11 @@ func_expr:func_name '(' ')' over_clause
1112211115n->agg_star =FALSE ;
1112311116n->agg_distinct =FALSE ;
1112411117n->func_variadic =TRUE ;
11125- n->over =$ 6 ;
11118+ n->over =NULL ;
1112611119n->location = @1 ;
1112711120$$ = (Node *)n;
1112811121}
11129- | func_name' (' func_arg_list' ,' VARIADIC func_arg_expr' )' over_clause
11122+ | func_name' (' func_arg_list' ,' VARIADIC func_arg_expr' )'
1113011123{
1113111124FuncCall *n =makeNode (FuncCall);
1113211125n->funcname = $1 ;
@@ -11135,11 +11128,11 @@ func_expr:func_name '(' ')' over_clause
1113511128n->agg_star =FALSE ;
1113611129n->agg_distinct =FALSE ;
1113711130n->func_variadic =TRUE ;
11138- n->over =$ 8 ;
11131+ n->over =NULL ;
1113911132n->location = @1 ;
1114011133$$ = (Node *)n;
1114111134}
11142- | func_name' (' func_arg_list sort_clause' )' over_clause
11135+ | func_name' (' func_arg_list sort_clause' )'
1114311136{
1114411137FuncCall *n =makeNode (FuncCall);
1114511138n->funcname = $1 ;
@@ -11148,11 +11141,11 @@ func_expr:func_name '(' ')' over_clause
1114811141n->agg_star =FALSE ;
1114911142n->agg_distinct =FALSE ;
1115011143n->func_variadic =FALSE ;
11151- n->over =$ 6 ;
11144+ n->over =NULL ;
1115211145n->location = @1 ;
1115311146$$ = (Node *)n;
1115411147}
11155- | func_name' (' ALL func_arg_list opt_sort_clause' )' over_clause
11148+ | func_name' (' ALL func_arg_list opt_sort_clause' )'
1115611149{
1115711150FuncCall *n =makeNode (FuncCall);
1115811151n->funcname = $1 ;
@@ -11165,11 +11158,11 @@ func_expr:func_name '(' ')' over_clause
1116511158 * for that in FuncCall at the moment.
1116611159*/
1116711160n->func_variadic =FALSE ;
11168- n->over =$ 7 ;
11161+ n->over =NULL ;
1116911162n->location = @1 ;
1117011163$$ = (Node *)n;
1117111164}
11172- | func_name' (' DISTINCT func_arg_list opt_sort_clause' )' over_clause
11165+ | func_name' (' DISTINCT func_arg_list opt_sort_clause' )'
1117311166{
1117411167FuncCall *n =makeNode (FuncCall);
1117511168n->funcname = $1 ;
@@ -11178,11 +11171,11 @@ func_expr:func_name '(' ')' over_clause
1117811171n->agg_star =FALSE ;
1117911172n->agg_distinct =TRUE ;
1118011173n->func_variadic =FALSE ;
11181- n->over =$ 7 ;
11174+ n->over =NULL ;
1118211175n->location = @1 ;
1118311176$$ = (Node *)n;
1118411177}
11185- | func_name' (' ' *' ' )' over_clause
11178+ | func_name' (' ' *' ' )'
1118611179{
1118711180/*
1118811181 * We consider AGGREGATE(*) to invoke a parameterless
@@ -11201,11 +11194,48 @@ func_expr:func_name '(' ')' over_clause
1120111194n->agg_star =TRUE ;
1120211195n->agg_distinct =FALSE ;
1120311196n->func_variadic =FALSE ;
11204- n->over =$ 5 ;
11197+ n->over =NULL ;
1120511198n->location = @1 ;
1120611199$$ = (Node *)n;
1120711200}
11208- | COLLATION FOR' (' a_expr' )'
11201+ ;
11202+
11203+
11204+ /*
11205+ * func_expr and its cousin func_expr_windowless is split out from c_expr just
11206+ * so that we have classifications for "everything that is a function call or
11207+ * looks like one". This isn't very important, but it saves us having to document
11208+ * which variants are legal in the backwards-compatible functional-index syntax
11209+ * for CREATE INDEX.
11210+ * (Note that many of the special SQL functions wouldn't actually make any
11211+ * sense as functional index entries, but we ignore that consideration here.)
11212+ */
11213+ func_expr: func_application over_clause
11214+ {
11215+ FuncCall *n = (FuncCall*)$1 ;
11216+ n->over = $2 ;
11217+ $$ = (Node*)n;
11218+ }
11219+ | func_expr_common_subexpr
11220+ { $$ = $1 ; }
11221+ ;
11222+
11223+ /*
11224+ * As func_expr but does not accept WINDOW functions directly (they
11225+ * can still be contained in arguments for functions etc.)
11226+ * Use this when window expressions are not allowed, so to disambiguate
11227+ * the grammar. (e.g. in CREATE INDEX)
11228+ */
11229+ func_expr_windowless:
11230+ func_application{ $$ = $1 ; }
11231+ | func_expr_common_subexpr { $$ = $1 ; }
11232+ ;
11233+
11234+ /*
11235+ * Special expression
11236+ */
11237+ func_expr_common_subexpr:
11238+ COLLATION FOR' (' a_expr' )'
1120911239{
1121011240FuncCall *n =makeNode (FuncCall);
1121111241n->funcname =SystemFuncName (" pg_collation_for" );
@@ -12794,6 +12824,7 @@ unreserved_keyword:
1279412824| OPERATOR
1279512825| OPTION
1279612826| OPTIONS
12827+ | OVER
1279712828| OWNED
1279812829| OWNER
1279912830| PARSER
@@ -12992,7 +13023,6 @@ type_func_name_keyword:
1299213023| NATURAL
1299313024| NOTNULL
1299413025| OUTER_P
12995- | OVER
1299613026| OVERLAPS
1299713027| RIGHT
1299813028| SIMILAR