Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 912c27f

Browse files
committed
Split out everything that looks like a function call from c_expr into
a separate production func_expr. This allows us to accept all these variants in the backwards-compatible syntax for creating a functional index; which beats documenting exactly which things work and which don't. Interestingly, it also seems to make the generated state machine a little bit smaller.
1 parent 2cda039 commit 912c27f

File tree

1 file changed

+55
-49
lines changed

1 file changed

+55
-49
lines changed

src/backend/parser/gram.y

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.475 2004/08/29 04:12:35 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.476 2004/09/29 23:39:20 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -272,8 +272,8 @@ static void doNegateFloat(Value *v);
272272
%type <node> columnDef
273273
%type <defelt> def_elem
274274
%type <node> def_arg columnElem where_clause
275-
a_expr b_expr c_expr AexprConst indirection_el columnref
276-
in_expr having_clause func_table array_expr
275+
a_expr b_expr c_expr func_expr AexprConst indirection_el
276+
columnref in_expr having_clause func_table array_expr
277277
%type <list> row type_list array_expr_list
278278
%type <node> case_expr case_arg when_clause case_default
279279
%type <list> when_clause_list
@@ -3238,18 +3238,12 @@ index_elem: ColId opt_class
32383238
$$->expr = NULL;
32393239
$$->opclass = $2;
32403240
}
3241-
| func_name '(' expr_list ')' opt_class
3241+
| func_expr opt_class
32423242
{
3243-
FuncCall *n = makeNode(FuncCall);
3244-
n->funcname = $1;
3245-
n->args = $3;
3246-
n->agg_star = FALSE;
3247-
n->agg_distinct = FALSE;
3248-
32493243
$$ = makeNode(IndexElem);
32503244
$$->name = NULL;
3251-
$$->expr = (Node *)n;
3252-
$$->opclass = $5;
3245+
$$->expr = $1;
3246+
$$->opclass = $2;
32533247
}
32543248
| '(' a_expr ')' opt_class
32553249
{
@@ -6479,7 +6473,55 @@ c_expr: columnref { $$ = $1; }
64796473
}
64806474
| case_expr
64816475
{ $$ = $1; }
6482-
| func_name '(' ')'
6476+
| func_expr
6477+
{ $$ = $1; }
6478+
| select_with_parens %prec UMINUS
6479+
{
6480+
SubLink *n = makeNode(SubLink);
6481+
n->subLinkType = EXPR_SUBLINK;
6482+
n->lefthand = NIL;
6483+
n->operName = NIL;
6484+
n->subselect = $1;
6485+
$$ = (Node *)n;
6486+
}
6487+
| EXISTS select_with_parens
6488+
{
6489+
SubLink *n = makeNode(SubLink);
6490+
n->subLinkType = EXISTS_SUBLINK;
6491+
n->lefthand = NIL;
6492+
n->operName = NIL;
6493+
n->subselect = $2;
6494+
$$ = (Node *)n;
6495+
}
6496+
| ARRAY select_with_parens
6497+
{
6498+
SubLink *n = makeNode(SubLink);
6499+
n->subLinkType = ARRAY_SUBLINK;
6500+
n->lefthand = NIL;
6501+
n->operName = NIL;
6502+
n->subselect = $2;
6503+
$$ = (Node *)n;
6504+
}
6505+
| ARRAY array_expr
6506+
{ $$ = $2; }
6507+
| row
6508+
{
6509+
RowExpr *r = makeNode(RowExpr);
6510+
r->args = $1;
6511+
r->row_typeid = InvalidOid; /* not analyzed yet */
6512+
$$ = (Node *)r;
6513+
}
6514+
;
6515+
6516+
/*
6517+
* func_expr is split out from c_expr just so that we have a classification
6518+
* for "everything that is a function call or looks like one". This isn't
6519+
* very important, but it saves us having to document which variants are
6520+
* legal in the backwards-compatible functional-index syntax for CREATE INDEX.
6521+
* (Note that many of the special SQL functions wouldn't actually make any
6522+
* sense as functional index entries, but we ignore that consideration here.)
6523+
*/
6524+
func_expr: func_name '(' ')'
64836525
{
64846526
FuncCall *n = makeNode(FuncCall);
64856527
n->funcname = $1;
@@ -6936,42 +6978,6 @@ c_expr: columnref { $$ = $1; }
69366978
n->agg_distinct = FALSE;
69376979
$$ = (Node *)n;
69386980
}
6939-
| select_with_parens %prec UMINUS
6940-
{
6941-
SubLink *n = makeNode(SubLink);
6942-
n->subLinkType = EXPR_SUBLINK;
6943-
n->lefthand = NIL;
6944-
n->operName = NIL;
6945-
n->subselect = $1;
6946-
$$ = (Node *)n;
6947-
}
6948-
| EXISTS select_with_parens
6949-
{
6950-
SubLink *n = makeNode(SubLink);
6951-
n->subLinkType = EXISTS_SUBLINK;
6952-
n->lefthand = NIL;
6953-
n->operName = NIL;
6954-
n->subselect = $2;
6955-
$$ = (Node *)n;
6956-
}
6957-
| ARRAY select_with_parens
6958-
{
6959-
SubLink *n = makeNode(SubLink);
6960-
n->subLinkType = ARRAY_SUBLINK;
6961-
n->lefthand = NIL;
6962-
n->operName = NIL;
6963-
n->subselect = $2;
6964-
$$ = (Node *)n;
6965-
}
6966-
| ARRAY array_expr
6967-
{ $$ = $2; }
6968-
| row
6969-
{
6970-
RowExpr *r = makeNode(RowExpr);
6971-
r->args = $1;
6972-
r->row_typeid = InvalidOid; /* not analyzed yet */
6973-
$$ = (Node *)r;
6974-
}
69756981
;
69766982

69776983
/*

0 commit comments

Comments
 (0)