Skip to content

Commit a50fcc0

Browse files
okbob@github.comCommitfest Bot
authored and
Commitfest Bot
committed
allow to use standard syntax for named arguments for plpgsql cursor arguments
1 parent 00d61a0 commit a50fcc0

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

doc/src/sgml/plpgsql.sgml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3317,7 +3317,7 @@ OPEN curs1 FOR EXECUTE format('SELECT * FROM %I WHERE col1 = $1',tabname) USING
33173317
<title>Opening a Bound Cursor</title>
33183318

33193319
<synopsis>
3320-
OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable> := </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional>;
3320+
OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable> { := | => } </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional>;
33213321
</synopsis>
33223322

33233323
<para>
@@ -3352,6 +3352,7 @@ OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replace
33523352
OPEN curs2;
33533353
OPEN curs3(42);
33543354
OPEN curs3(key := 42);
3355+
OPEN curs3(Key => 42);
33553356
</programlisting>
33563357
</para>
33573358

src/pl/plpgsql/src/pl_gram.y

+8-5
Original file line numberDiff line numberDiff line change
@@ -3955,9 +3955,12 @@ read_cursor_args(PLpgSQL_var *cursor, int until, YYSTYPE *yylvalp, YYLTYPE *yyll
39553955
tok2;
39563956
int arglocation;
39573957

3958-
/* Check if it's a named parameter: "param := value" */
3958+
/*
3959+
* Check if it's a named parameter: "param := value"
3960+
* or "param => value"
3961+
*/
39593962
plpgsql_peek2(&tok1, &tok2, &arglocation, NULL, yyscanner);
3960-
if (tok1 == IDENT && tok2 == COLON_EQUALS)
3963+
if (tok1 == IDENT && (tok2 == COLON_EQUALS || tok2 == EQUALS_GREATER))
39613964
{
39623965
char *argname;
39633966
IdentifierLookup save_IdentifierLookup;
@@ -3983,11 +3986,11 @@ read_cursor_args(PLpgSQL_var *cursor, int until, YYSTYPE *yylvalp, YYLTYPE *yyll
39833986
parser_errposition(*yyllocp)));
39843987

39853988
/*
3986-
* Eat the ":=". We already peeked, so the error should never
3987-
* happen.
3989+
* Eat the ":=" and the "=>". We already peeked, so the error should
3990+
* never happen.
39883991
*/
39893992
tok2 = yylex(yylvalp, yyllocp, yyscanner);
3990-
if (tok2 != COLON_EQUALS)
3993+
if (tok2 != COLON_EQUALS && tok2 != EQUALS_GREATER)
39913994
yyerror(yyllocp, NULL, yyscanner, "syntax error");
39923995

39933996
any_named = true;

src/test/regress/expected/plpgsql.out

+2-1
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,8 @@ declare
24192419
p2 int4 := 1006;
24202420
n int4;
24212421
begin
2422-
open c1 (p1 := p1, p2 := p2, debug := 2);
2422+
-- use both supported syntaxes for named arguments
2423+
open c1 (p1 := p1, p2 => p2, debug => 2);
24232424
fetch c1 into n;
24242425
return n;
24252426
end $$ language plpgsql;

src/test/regress/sql/plpgsql.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,8 @@ declare
20722072
p2 int4 := 1006;
20732073
n int4;
20742074
begin
2075-
open c1 (p1 := p1, p2 := p2, debug := 2);
2075+
-- use both supported syntaxes for named arguments
2076+
open c1 (p1 := p1, p2 => p2, debug => 2);
20762077
fetch c1 into n;
20772078
return n;
20782079
end $$ language plpgsql;

0 commit comments

Comments
 (0)