Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf065957

Browse files
committed
Come to think of it, functions in FROM have the same syntactic restriction
as CREATE INDEX did, and can be fixed the same way, for another smallimprovement in usability and reduction in grammar size.
1 parent912c27f commitf065957

File tree

4 files changed

+26
-51
lines changed

4 files changed

+26
-51
lines changed

‎src/backend/parser/gram.y

Lines changed: 13 additions & 42 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.476 2004/09/29 23:39:20 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.477 2004/09/30 00:24:20 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -5368,24 +5368,7 @@ relation_expr:
53685368
;
53695369

53705370

5371-
func_table: func_name'('')'
5372-
{
5373-
FuncCall *n = makeNode(FuncCall);
5374-
n->funcname =$1;
5375-
n->args = NIL;
5376-
n->agg_star =FALSE;
5377-
n->agg_distinct =FALSE;
5378-
$$ = (Node *)n;
5379-
}
5380-
| func_name'(' expr_list')'
5381-
{
5382-
FuncCall *n = makeNode(FuncCall);
5383-
n->funcname =$1;
5384-
n->args =$3;
5385-
n->agg_star =FALSE;
5386-
n->agg_distinct =FALSE;
5387-
$$ = (Node *)n;
5388-
}
5371+
func_table: func_expr{$$ =$1; }
53895372
;
53905373

53915374

@@ -6978,6 +6961,16 @@ func_expr:func_name '(' ')'
69786961
n->agg_distinct =FALSE;
69796962
$$ = (Node *)n;
69806963
}
6964+
| NULLIF'(' a_expr',' a_expr')'
6965+
{
6966+
$$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF,"=",$3,$5);
6967+
}
6968+
| COALESCE'(' expr_list')'
6969+
{
6970+
CoalesceExpr *c = makeNode(CoalesceExpr);
6971+
c->args =$3;
6972+
$$ = (Node *)c;
6973+
}
69816974
;
69826975

69836976
/*
@@ -7206,24 +7199,12 @@ in_expr:select_with_parens
72067199
|'(' expr_list')'{$$ = (Node *)$2; }
72077200
;
72087201

7209-
/* Case clause
7202+
/*
72107203
* Define SQL92-style case clause.
7211-
* Allow all four forms described in the standard:
72127204
* - Full specification
72137205
*CASE WHEN a = b THEN c ... ELSE d END
72147206
* - Implicit argument
72157207
*CASE a WHEN b THEN c ... ELSE d END
7216-
* - Conditional NULL
7217-
*NULLIF(x,y)
7218-
*same as CASE WHEN x = y THEN NULL ELSE x END
7219-
* - Conditional substitution from list, use first non-null argument
7220-
*COALESCE(a,b,...)
7221-
* same as CASE WHEN a IS NOT NULL THEN a WHEN b IS NOT NULL THEN b ... END
7222-
* - thomas 1998-11-09
7223-
*
7224-
* NULLIF and COALESCE have become first class nodes to
7225-
* prevent double evaluation of arguments.
7226-
* - Kris Jurka 2003-02-11
72277208
*/
72287209
case_expr:CASE case_arg when_clause_list case_default END_P
72297210
{
@@ -7234,16 +7215,6 @@ case_expr:CASE case_arg when_clause_list case_default END_P
72347215
c->defresult = (Expr *)$4;
72357216
$$ = (Node *)c;
72367217
}
7237-
| NULLIF'(' a_expr',' a_expr')'
7238-
{
7239-
$$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF,"=",$3,$5);
7240-
}
7241-
| COALESCE'(' expr_list')'
7242-
{
7243-
CoalesceExpr *c = makeNode(CoalesceExpr);
7244-
c->args =$3;
7245-
$$ = (Node *)c;
7246-
}
72477218
;
72487219

72497220
when_clause_list:

‎src/backend/parser/parse_clause.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.136 2004/08/29 05:06:44 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.137 2004/09/30 00:24:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -497,12 +497,16 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r)
497497
RangeTblEntry*rte;
498498
RangeTblRef*rtr;
499499

500-
/* Get function name for possible use as alias */
501-
Assert(IsA(r->funccallnode,FuncCall));
502-
funcname=strVal(llast(((FuncCall*)r->funccallnode)->funcname));
500+
/*
501+
* Get function name for possible use as alias. We use the same
502+
* transformation rules as for a SELECT output expression. For a
503+
* FuncCall node, the result will be the function name, but it is
504+
* possible for the grammar to hand back other node types.
505+
*/
506+
funcname=FigureColname(r->funccallnode);
503507

504508
/*
505-
* Transform the rawFuncCall node.
509+
* Transform the rawexpression.
506510
*/
507511
funcexpr=transformExpr(pstate,r->funccallnode);
508512

‎src/backend/parser/parse_target.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.125 2004/08/29 05:06:44 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.126 2004/09/30 00:24:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -41,7 +41,6 @@ static Node *transformAssignmentIndirection(ParseState *pstate,
4141
staticList*ExpandColumnRefStar(ParseState*pstate,ColumnRef*cref);
4242
staticList*ExpandAllTables(ParseState*pstate);
4343
staticList*ExpandIndirectionStar(ParseState*pstate,A_Indirection*ind);
44-
staticchar*FigureColname(Node*node);
4544
staticintFigureColnameInternal(Node*node,char**name);
4645

4746

@@ -893,7 +892,7 @@ ExpandIndirectionStar(ParseState *pstate, A_Indirection *ind)
893892
* Note that the argument is the *untransformed* parse tree for the target
894893
* item. This is a shade easier to work with than the transformed tree.
895894
*/
896-
staticchar*
895+
char*
897896
FigureColname(Node*node)
898897
{
899898
char*name=NULL;

‎src/include/parser/parse_target.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/parser/parse_target.h,v 1.33 2004/08/29 04:13:09 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/parser/parse_target.h,v 1.34 2004/09/30 00:24:27 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,5 +27,6 @@ extern void updateTargetListEntry(ParseState *pstate, TargetEntry *tle,
2727
List*indirection);
2828
externList*checkInsertTargets(ParseState*pstate,List*cols,
2929
List**attrnos);
30+
externchar*FigureColname(Node*node);
3031

3132
#endif/* PARSE_TARGET_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp