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

Commit246dedc

Browse files
committed
Allow => syntax for named cursor arguments in plpgsql.
We've traditionally accepted "name := value" syntax forcursor arguments in plpgsql. But it turns out that theequivalent statements in Oracle use "name => value".Since we accept both forms of punctuation for functionarguments, it makes sense to do the same here.Author: Pavel Stehule <pavel.stehule@gmail.com>Reviewed-by: Gilles Darold <gilles@darold.net>Discussion:https://postgr.es/m/CAFj8pRA3d0ARQEMbABa1n6q25AUdNmyO8aGs56XNf9pD4sRMjQ@mail.gmail.com
1 parentb6904af commit246dedc

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 5 additions & 3 deletions
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>{ := | =&gt; } </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional>;
33213321
</synopsis>
33223322

33233323
<para>
@@ -3340,7 +3340,8 @@ OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replace
33403340
Argument values can be passed using either <firstterm>positional</firstterm>
33413341
or <firstterm>named</firstterm> notation. In positional
33423342
notation, all arguments are specified in order. In named notation,
3343-
each argument's name is specified using <literal>:=</literal> to
3343+
each argument's name is specified using <literal>:=</literal>
3344+
or <literal>=&gt;</literal> to
33443345
separate it from the argument expression. Similar to calling
33453346
functions, described in <xref linkend="sql-syntax-calling-funcs"/>, it
33463347
is also allowed to mix positional and named notation.
@@ -3352,6 +3353,7 @@ OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replace
33523353
OPEN curs2;
33533354
OPEN curs3(42);
33543355
OPEN curs3(key := 42);
3356+
OPEN curs3(key =&gt; 42);
33553357
</programlisting>
33563358
</para>
33573359

@@ -3672,7 +3674,7 @@ COMMIT;
36723674

36733675
<synopsis>
36743676
<optional> &lt;&lt;<replaceable>label</replaceable>&gt;&gt; </optional>
3675-
FOR <replaceable>recordvar</replaceable> IN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable>:= </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional> LOOP
3677+
FOR <replaceable>recordvar</replaceable> IN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable>{ := | =&gt; } </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional> LOOP
36763678
<replaceable>statements</replaceable>
36773679
END LOOP <optional> <replaceable>label</replaceable> </optional>;
36783680
</synopsis>

‎src/pl/plpgsql/src/pl_gram.y

Lines changed: 8 additions & 5 deletions
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
intarglocation;
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 ":=" or "=>".We already peeked, so the error should
3990+
*neverhappen.
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

Lines changed: 4 additions & 2 deletions
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;
@@ -3487,7 +3488,8 @@ begin
34873488
raise notice '% from %', r.i, c;
34883489
end loop;
34893490
-- again, to test if cursor was closed properly
3490-
for r in c(9,10) loop
3491+
-- (and while we're at it, test named-parameter notation)
3492+
for r in c(r2 := 10, r1 => 9) loop
34913493
raise notice '% from %', r.i, c;
34923494
end loop;
34933495
-- and test a parameterless cursor

‎src/test/regress/sql/plpgsql.sql

Lines changed: 4 additions & 2 deletions
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;
@@ -2934,7 +2935,8 @@ begin
29342935
raise notice'% from %',r.i, c;
29352936
end loop;
29362937
-- again, to test if cursor was closed properly
2937-
for rin c(9,10) loop
2938+
-- (and while we're at it, test named-parameter notation)
2939+
for rin c(r2 :=10, r1=>9) loop
29382940
raise notice'% from %',r.i, c;
29392941
end loop;
29402942
-- and test a parameterless cursor

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp