1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Allow named parameters to be specified using => in addition to :=

SQL has standardized on => as the use of to specify named parameters,
and we've wanted for many years to support the same syntax ourselves,
but this has been complicated by the possible use of => as an operator
name.  In PostgreSQL 9.0, we began emitting a warning when an operator
named => was defined, and in PostgreSQL 9.2, we stopped shipping a
=>(text, text) operator as part of hstore.  By the time the next major
version of PostgreSQL is released, => will have been deprecated for a
full five years, so hopefully there won't be too many people still
relying on it.  We continue to support := for compatibility with
previous PostgreSQL releases.

Pavel Stehule, reviewed by Petr Jelinek, with a few documentation
tweaks by me.
This commit is contained in:
Robert Haas
2015-03-10 10:59:11 -04:00
parent 4f3924d9cd
commit 865f14a2d3
10 changed files with 124 additions and 24 deletions

View File

@@ -6785,7 +6785,7 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
Create interval from years, months, weeks, days, hours, minutes and
seconds fields
</entry>
<entry><literal>make_interval(days := 10)</literal></entry>
<entry><literal>make_interval(days => 10)</literal></entry>
<entry><literal>10 days</literal></entry>
</row>

View File

@@ -2596,10 +2596,10 @@ SELECT concat_lower_or_upper('Hello', 'World');
<para>
In named notation, each argument's name is specified using
<literal>:=</literal> to separate it from the argument expression.
<literal>=></literal> to separate it from the argument expression.
For example:
<screen>
SELECT concat_lower_or_upper(a := 'Hello', b := 'World');
SELECT concat_lower_or_upper(a => 'Hello', b => 'World');
concat_lower_or_upper
-----------------------
hello world
@@ -2610,13 +2610,24 @@ SELECT concat_lower_or_upper(a := 'Hello', b := 'World');
using named notation is that the arguments may be specified in any
order, for example:
<screen>
SELECT concat_lower_or_upper(a := 'Hello', b := 'World', uppercase := true);
SELECT concat_lower_or_upper(a => 'Hello', b => 'World', uppercase => true);
concat_lower_or_upper
-----------------------
HELLO WORLD
(1 row)
SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World');
SELECT concat_lower_or_upper(a => 'Hello', uppercase => true, b => 'World');
concat_lower_or_upper
-----------------------
HELLO WORLD
(1 row)
</screen>
</para>
<para>
An older syntax based on ":=" is supported for backward compatibility:
<screen>
SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World');
concat_lower_or_upper
-----------------------
HELLO WORLD
@@ -2638,7 +2649,7 @@ SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World');
already mentioned, named arguments cannot precede positional arguments.
For example:
<screen>
SELECT concat_lower_or_upper('Hello', 'World', uppercase := true);
SELECT concat_lower_or_upper('Hello', 'World', uppercase => true);
concat_lower_or_upper
-----------------------
HELLO WORLD

View File

@@ -776,14 +776,14 @@ SELECT mleast(VARIADIC ARRAY[]::numeric[]);
<literal>VARIADIC</>. For example, this will work:
<screen>
SELECT mleast(VARIADIC arr := ARRAY[10, -1, 5, 4.4]);
SELECT mleast(VARIADIC arr => ARRAY[10, -1, 5, 4.4]);
</screen>
but not these:
<screen>
SELECT mleast(arr := 10);
SELECT mleast(arr := ARRAY[10, -1, 5, 4.4]);
SELECT mleast(arr => 10);
SELECT mleast(arr => ARRAY[10, -1, 5, 4.4]);
</screen>
</para>
</sect2>