Home Explore Blog CI



postgresql

36th chunk of `doc/src/sgml/syntax.sgml`
a453dcdb92f0349bfd24b5a7783567db1e7d9fae33c9d4b00000000100000c6c
 are specified in order.  The result is upper case since
     <literal>uppercase</literal> is specified as <literal>true</literal>.
     Another example is:
<screen>
SELECT concat_lower_or_upper('Hello', 'World');
 concat_lower_or_upper
-----------------------
 hello world
(1 row)
</screen>
     Here, the <literal>uppercase</literal> parameter is omitted, so it
     receives its default value of <literal>false</literal>, resulting in
     lower case output.  In positional notation, arguments can be omitted
     from right to left so long as they have defaults.
    </para>
   </sect2>

   <sect2 id="sql-syntax-calling-funcs-named">
    <title>Using Named Notation</title>

    <indexterm>
     <primary>function</primary>
     <secondary>named notation</secondary>
    </indexterm>

    <para>
     In named notation, each argument's name is specified using
     <literal>=&gt;</literal> to separate it from the argument expression.
     For example:
<screen>
SELECT concat_lower_or_upper(a =&gt; 'Hello', b =&gt; 'World');
 concat_lower_or_upper
-----------------------
 hello world
(1 row)
</screen>
     Again, the argument <literal>uppercase</literal> was omitted
     so it is set to <literal>false</literal> implicitly.  One advantage of
     using named notation is that the arguments may be specified in any
     order, for example:
<screen>
SELECT concat_lower_or_upper(a =&gt; 'Hello', b =&gt; 'World', uppercase =&gt; true);
 concat_lower_or_upper
-----------------------
 HELLO WORLD
(1 row)

SELECT concat_lower_or_upper(a =&gt; 'Hello', uppercase =&gt; true, b =&gt; '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
(1 row)
</screen>
    </para>
   </sect2>

  <sect2 id="sql-syntax-calling-funcs-mixed">
   <title>Using Mixed Notation</title>

   <indexterm>
    <primary>function</primary>
    <secondary>mixed notation</secondary>
   </indexterm>

   <para>
    The mixed notation combines positional and named notation. However, as
    already mentioned, named arguments cannot precede positional arguments.
    For example:
<screen>
SELECT concat_lower_or_upper('Hello', 'World', uppercase =&gt; true);
 concat_lower_or_upper
-----------------------
 HELLO WORLD
(1 row)
</screen>
    In the above query, the arguments <literal>a</literal> and
    <literal>b</literal> are specified positionally, while
    <literal>uppercase</literal> is specified by name.  In this example,
    that adds little except documentation.  With a more complex function
    having numerous parameters that have default values, named or mixed
    notation can save a great deal of writing and reduce chances for error.
   </para>

   <note>
    <para>
     Named and mixed call notations currently cannot be used when calling an
     aggregate function (but they do work when an aggregate function is used
     as a window function).
    </para>
   </note>
  </sect2>
 </sect1>

</chapter>

Title: Named and Mixed Notation for Function Calls in PostgreSQL
Summary
This section details named notation for function calls in PostgreSQL, where arguments are specified with their names using `=>`, allowing for arbitrary order. An older `:=` syntax is also supported. The section then explains mixed notation, which combines positional and named arguments, with the constraint that named arguments cannot precede positional ones. Mixed notation is useful for complex functions with many default parameters, improving readability and reducing errors. It also notes that named and mixed notations cannot be used when calling an aggregate function, except when it's used as a window function.