<title>Opening a Bound Cursor</title>
<synopsis>
-OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable> := </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional>;
+OPEN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable> { := | => } </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional>;
</synopsis>
<para>
Argument values can be passed using either <firstterm>positional</firstterm>
or <firstterm>named</firstterm> notation. In positional
notation, all arguments are specified in order. In named notation,
- each argument's name is specified using <literal>:=</literal> to
+ each argument's name is specified using <literal>:=</literal>
+ or <literal>=></literal> to
separate it from the argument expression. Similar to calling
functions, described in <xref linkend="sql-syntax-calling-funcs"/>, it
is also allowed to mix positional and named notation.
OPEN curs2;
OPEN curs3(42);
OPEN curs3(key := 42);
+OPEN curs3(key => 42);
</programlisting>
</para>
<synopsis>
<optional> <<<replaceable>label</replaceable>>> </optional>
-FOR <replaceable>recordvar</replaceable> IN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable> := </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional> LOOP
+FOR <replaceable>recordvar</replaceable> IN <replaceable>bound_cursorvar</replaceable> <optional> ( <optional> <replaceable>argument_name</replaceable> { := | => } </optional> <replaceable>argument_value</replaceable> <optional>, ...</optional> ) </optional> LOOP
<replaceable>statements</replaceable>
END LOOP <optional> <replaceable>label</replaceable> </optional>;
</synopsis>
tok2;
int arglocation;
- /* Check if it's a named parameter: "param := value" */
+ /*
+ * Check if it's a named parameter: "param := value"
+ * or "param => value"
+ */
plpgsql_peek2(&tok1, &tok2, &arglocation, NULL, yyscanner);
- if (tok1 == IDENT && tok2 == COLON_EQUALS)
+ if (tok1 == IDENT && (tok2 == COLON_EQUALS || tok2 == EQUALS_GREATER))
{
char *argname;
IdentifierLookup save_IdentifierLookup;
parser_errposition(*yyllocp)));
/*
- * Eat the ":=". We already peeked, so the error should never
- * happen.
+ * Eat the ":=" or "=>". We already peeked, so the error should
+ * never happen.
*/
tok2 = yylex(yylvalp, yyllocp, yyscanner);
- if (tok2 != COLON_EQUALS)
+ if (tok2 != COLON_EQUALS && tok2 != EQUALS_GREATER)
yyerror(yyllocp, NULL, yyscanner, "syntax error");
any_named = true;
p2 int4 := 1006;
n int4;
begin
- open c1 (p1 := p1, p2 := p2, debug := 2);
+ -- use both supported syntaxes for named arguments
+ open c1 (p1 := p1, p2 => p2, debug => 2);
fetch c1 into n;
return n;
end $$ language plpgsql;
raise notice '% from %', r.i, c;
end loop;
-- again, to test if cursor was closed properly
- for r in c(9,10) loop
+ -- (and while we're at it, test named-parameter notation)
+ for r in c(r2 := 10, r1 => 9) loop
raise notice '% from %', r.i, c;
end loop;
-- and test a parameterless cursor
p2 int4 := 1006;
n int4;
begin
- open c1 (p1 := p1, p2 := p2, debug := 2);
+ -- use both supported syntaxes for named arguments
+ open c1 (p1 := p1, p2 => p2, debug => 2);
fetch c1 into n;
return n;
end $$ language plpgsql;
raise notice '% from %', r.i, c;
end loop;
-- again, to test if cursor was closed properly
- for r in c(9,10) loop
+ -- (and while we're at it, test named-parameter notation)
+ for r in c(r2 := 10, r1 => 9) loop
raise notice '% from %', r.i, c;
end loop;
-- and test a parameterless cursor