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

Commit b12b7a9

Browse files
committed
Change the notation for calling functions with named parameters from
"val AS name" to "name := val", as per recent discussion. This patch catches everything in the original named-parameters patch, but I'm not certain that no other dependencies snuck in later (grepping the source tree for all uses of AS soon proved unworkable). In passing I note that we've dropped the ball at least once on keeping ecpg's lexer (as opposed to parser) in sync with the backend. It would be a good idea to go through all of pgc.l and see if it's in sync now. I didn't attempt that at the moment.
1 parent 2bde07c commit b12b7a9

File tree

11 files changed

+105
-102
lines changed

11 files changed

+105
-102
lines changed

doc/src/sgml/syntax.sgml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.144 2010/05/27 18:23:47 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.145 2010/05/30 18:10:40 tgl Exp $ -->
22

33
<chapter id="sql-syntax">
44
<title>SQL Syntax</title>
@@ -2285,10 +2285,11 @@ SELECT concat_lower_or_upper('Hello', 'World');
22852285
</indexterm>
22862286

22872287
<para>
2288-
In named notation, each argument's name is specified using the
2289-
<literal>AS</literal> keyword. For example:
2288+
In named notation, each argument's name is specified using
2289+
<literal>:=</literal> to separate it from the argument expression.
2290+
For example:
22902291
<screen>
2291-
SELECT concat_lower_or_upper('Hello' AS a, 'World' AS b);
2292+
SELECT concat_lower_or_upper(a := 'Hello', b := 'World');
22922293
concat_lower_or_upper
22932294
-----------------------
22942295
hello world
@@ -2299,13 +2300,13 @@ SELECT concat_lower_or_upper('Hello' AS a, 'World' AS b);
22992300
using named notation is that the arguments may be specified in any
23002301
order, for example:
23012302
<screen>
2302-
SELECT concat_lower_or_upper('Hello' AS a, 'World' AS b, true AS uppercase);
2303+
SELECT concat_lower_or_upper(a := 'Hello', b := 'World', uppercase := true);
23032304
concat_lower_or_upper
23042305
-----------------------
23052306
HELLO WORLD
23062307
(1 row)
23072308

2308-
SELECT concat_lower_or_upper('Hello' AS a, true AS uppercase, 'World' AS b);
2309+
SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World');
23092310
concat_lower_or_upper
23102311
-----------------------
23112312
HELLO WORLD
@@ -2327,7 +2328,7 @@ SELECT concat_lower_or_upper('Hello' AS a, true AS uppercase, 'World' AS b);
23272328
already mentioned, named arguments cannot precede positional arguments.
23282329
For example:
23292330
<screen>
2330-
SELECT concat_lower_or_upper('Hello', 'World', true AS uppercase);
2331+
SELECT concat_lower_or_upper('Hello', 'World', uppercase := true);
23312332
concat_lower_or_upper
23322333
-----------------------
23332334
HELLO WORLD

doc/src/sgml/xfunc.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.148 2010/05/16 04:35:04 rhaas Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.149 2010/05/30 18:10:40 tgl Exp $ -->
22

33
<sect1 id="xfunc">
44
<title>User-Defined Functions</title>
@@ -705,14 +705,14 @@ SELECT mleast(VARIADIC ARRAY[10, -1, 5, 4.4]);
705705
<literal>VARIADIC</>. For example, this will work:
706706

707707
<screen>
708-
SELECT mleast(VARIADIC ARRAY[10, -1, 5, 4.4] AS arr);
708+
SELECT mleast(VARIADIC arr := ARRAY[10, -1, 5, 4.4]);
709709
</screen>
710710

711711
but not these:
712712

713713
<screen>
714-
SELECT mleast(10 AS arr);
715-
SELECT mleast(ARRAY[10, -1, 5, 4.4] AS arr);
714+
SELECT mleast(arr := 10);
715+
SELECT mleast(arr := ARRAY[10, -1, 5, 4.4]);
716716
</screen>
717717
</para>
718718
</sect2>

src/backend/parser/gram.y

Lines changed: 8 additions & 8 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.711 2010/02/23 22:51:42 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.712 2010/05/30 18:10:40 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -444,8 +444,8 @@ static TypeName *TableFuncTypeName(List *columns);
444444
* the set of keywords. PL/pgsql depends on this so that it can share the
445445
* same lexer. If you add/change tokens here, fix PL/pgsql to match!
446446
*
447-
* DOT_DOT and COLON_EQUALS are unused in the core SQL grammar, and so will
448-
* always provoke parse errors. They are needed by PL/pgsql.
447+
* DOT_DOT is unused in the core SQL grammar, and so will always provoke
448+
* parse errors. It is needed by PL/pgsql.
449449
*/
450450
%token <str> IDENT FCONST SCONST BCONST XCONST Op
451451
%token <ival> ICONST PARAM
@@ -10212,13 +10212,13 @@ func_arg_expr: a_expr
1021210212
{
1021310213
$$ = $1;
1021410214
}
10215-
| a_expr AS param_name
10215+
| param_name COLON_EQUALS a_expr
1021610216
{
1021710217
NamedArgExpr *na = makeNode(NamedArgExpr);
10218-
na->arg = (Expr *) $1;
10219-
na->name = $3;
10218+
na->name = $1;
10219+
na->arg = (Expr *) $3;
1022010220
na->argnumber = -1; /* until determined */
10221-
na->location = @3;
10221+
na->location = @1;
1022210222
$$ = (Node *) na;
1022310223
}
1022410224
;
@@ -10698,7 +10698,7 @@ AexprConst: Iconst
1069810698
if (IsA(arg, NamedArgExpr))
1069910699
ereport(ERROR,
1070010700
(errcode(ERRCODE_SYNTAX_ERROR),
10701-
errmsg("type modifier cannot have AS name"),
10701+
errmsg("type modifier cannot have parameter name"),
1070210702
parser_errposition(arg->location)));
1070310703
}
1070410704
t->typmods = $3;

src/backend/parser/parse_func.c

Lines changed: 3 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_func.c,v 1.223 2010/03/17 16:52:38 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.224 2010/05/30 18:10:40 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1386,12 +1386,12 @@ funcname_signature_string(const char *funcname, int nargs,
13861386
{
13871387
if (i)
13881388
appendStringInfoString(&argbuf, ", ");
1389-
appendStringInfoString(&argbuf, format_type_be(argtypes[i]));
13901389
if (i >= numposargs)
13911390
{
1392-
appendStringInfo(&argbuf, " AS %s", (char *) lfirst(lc));
1391+
appendStringInfo(&argbuf, "%s := ", (char *) lfirst(lc));
13931392
lc = lnext(lc);
13941393
}
1394+
appendStringInfoString(&argbuf, format_type_be(argtypes[i]));
13951395
}
13961396

13971397
appendStringInfoChar(&argbuf, ')');

src/backend/parser/scan.l

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
2626
* IDENTIFICATION
27-
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.166 2010/01/16 17:39:55 tgl Exp $
27+
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.167 2010/05/30 18:10:41 tgl Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -317,8 +317,6 @@ ident_cont [A-Za-z\200-\377_0-9\$]
317317
identifier {ident_start}{ident_cont}*
318318

319319
typecast "::"
320-
321-
/* these two token types are used by PL/pgsql, though not in core SQL */
322320
dot_dot \.\.
323321
colon_equals ":="
324322

src/backend/utils/adt/ruleutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.325 2010/02/26 02:01:09 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.326 2010/05/30 18:10:41 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -4537,8 +4537,8 @@ get_rule_expr(Node *node, deparse_context *context,
45374537
{
45384538
NamedArgExpr *na = (NamedArgExpr *) node;
45394539

4540+
appendStringInfo(buf, "%s := ", quote_identifier(na->name));
45404541
get_rule_expr((Node *) na->arg, context, showimplicit);
4541-
appendStringInfo(buf, " AS %s", quote_identifier(na->name));
45424542
}
45434543
break;
45444544

src/bin/psql/psqlscan.l

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* Portions Copyright (c) 1994, Regents of the University of California
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.33 2010/05/05 22:18:56 tgl Exp $
36+
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.34 2010/05/30 18:10:41 tgl Exp $
3737
*
3838
*-------------------------------------------------------------------------
3939
*/
@@ -345,8 +345,6 @@ ident_cont [A-Za-z\200-\377_0-9\$]
345345
identifier {ident_start}{ident_cont}*
346346

347347
typecast "::"
348-
349-
/* these two token types are used by PL/pgsql, though not in core SQL */
350348
dot_dot \.\.
351349
colon_equals ":="
352350

src/interfaces/ecpg/preproc/parse.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl
2-
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parse.pl,v 1.7 2010/01/02 16:58:11 momjian Exp $
2+
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parse.pl,v 1.8 2010/05/30 18:10:41 tgl Exp $
33
# parser generater for ecpg
44
# call with backend parser as stdin
55
#
@@ -41,6 +41,8 @@
4141
$replace_string{'NULLS_FIRST'} = 'nulls first';
4242
$replace_string{'NULLS_LAST'} = 'nulls last';
4343
$replace_string{'TYPECAST'} = '::';
44+
$replace_string{'DOT_DOT'} = '..';
45+
$replace_string{'COLON_EQUALS'} = ':=';
4446

4547
# specific replace_types for specific non-terminals - never include the ':'
4648
# ECPG-only replace_types are defined in ecpg-replace_types

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.173 2010/03/21 10:49:51 meskes Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.174 2010/05/30 18:10:41 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -230,6 +230,8 @@ identifier {ident_start}{ident_cont}*
230230

231231
array ({ident_cont}|{whitespace}|[\[\]\+\-\*\%\/\(\)\>\.])*
232232
typecast "::"
233+
dot_dot \.\.
234+
colon_equals ":="
233235

234236
/*
235237
* "self" is the set of chars that should be returned as single-character
@@ -595,6 +597,8 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
595597
}
596598
<xdc>{xdcinside} { addlit(yytext, yyleng); }
597599
<SQL>{typecast} { return TYPECAST; }
600+
<SQL>{dot_dot} { return DOT_DOT; }
601+
<SQL>{colon_equals} { return COLON_EQUALS; }
598602
<SQL>{informix_special} {
599603
/* are we simulating Informix? */
600604
if (INFORMIX_MODE)

0 commit comments

Comments
 (0)