mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Support INOUT arguments in procedures
In a top-level CALL, the values of INOUT arguments will be returned as a result row. In PL/pgSQL, the values are assigned back to the input arguments. In other languages, the same convention as for return a record from a function is used. That does not require any code changes in the PL implementations. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
This commit is contained in:
@ -278,6 +278,20 @@ SELECT * FROM perl_row();
|
||||
hash will be returned as null values.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Similarly, output arguments of procedures can be returned as a hash
|
||||
reference:
|
||||
|
||||
<programlisting>
|
||||
CREATE PROCEDURE perl_triple(INOUT a integer, INOUT b integer) AS $$
|
||||
my ($a, $b) = @_;
|
||||
return {a => $a * 3, b => $b * 3};
|
||||
$$ LANGUAGE plperl;
|
||||
|
||||
CALL perl_triple(5, 10);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
PL/Perl functions can also return sets of either scalar or
|
||||
composite types. Usually you'll want to return rows one at a
|
||||
|
@ -1870,6 +1870,22 @@ SELECT * FROM get_available_flightid(CURRENT_DATE);
|
||||
then <symbol>NULL</symbol> must be returned. Returning any other value
|
||||
will result in an error.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If a procedure has output parameters, then the output values can be
|
||||
assigned to the parameters as if they were variables. For example:
|
||||
<programlisting>
|
||||
CREATE PROCEDURE triple(INOUT x int)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
x := x * 3;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CALL triple(5);
|
||||
</programlisting>
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="plpgsql-conditionals">
|
||||
|
@ -649,6 +649,17 @@ return (1, 2)
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
SELECT * FROM multiout_simple();
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Output parameters of procedures are passed back the same way. For example:
|
||||
<programlisting>
|
||||
CREATE PROCEDURE python_triple(INOUT a integer, INOUT b integer) AS $$
|
||||
return (a * 3, b * 3)
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CALL python_triple(5, 10);
|
||||
</programlisting>
|
||||
</para>
|
||||
</sect2>
|
||||
|
@ -186,6 +186,18 @@ $$ LANGUAGE pltcl;
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Output arguments of procedures are returned in the same way, for example:
|
||||
|
||||
<programlisting>
|
||||
CREATE PROCEDURE tcl_triple(INOUT a integer, INOUT b integer) AS $$
|
||||
return [list a [expr {$1 * 3}] b [expr {$2 * 3}]]
|
||||
$$ LANGUAGE pltcl;
|
||||
|
||||
CALL tcl_triple(5, 10);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<tip>
|
||||
<para>
|
||||
The result list can be made from an array representation of the
|
||||
|
@ -31,6 +31,10 @@ CALL <replaceable class="parameter">name</replaceable> ( [ <replaceable class="p
|
||||
<para>
|
||||
<command>CALL</command> executes a procedure.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If the procedure has output arguments, then a result row will be returned.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@ -96,8 +96,11 @@ CREATE [ OR REPLACE ] PROCEDURE
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The mode of an argument: <literal>IN</literal> or <literal>VARIADIC</literal>.
|
||||
If omitted, the default is <literal>IN</literal>.
|
||||
The mode of an argument: <literal>IN</literal>,
|
||||
<literal>INOUT</literal>, or <literal>VARIADIC</literal>. If omitted,
|
||||
the default is <literal>IN</literal>. (<literal>OUT</literal>
|
||||
arguments are currently not supported for procedures. Use
|
||||
<literal>INOUT</literal> instead.)
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
Reference in New Issue
Block a user