From 33803f67f1c4cb88733cce61207bbf2bd5b599cc Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 14 Mar 2018 11:47:21 -0400 Subject: 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 --- doc/src/sgml/plperl.sgml | 14 ++++++++++++++ doc/src/sgml/plpgsql.sgml | 16 ++++++++++++++++ doc/src/sgml/plpython.sgml | 11 +++++++++++ doc/src/sgml/pltcl.sgml | 12 ++++++++++++ doc/src/sgml/ref/call.sgml | 4 ++++ doc/src/sgml/ref/create_procedure.sgml | 7 +++++-- 6 files changed, 62 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plperl.sgml b/doc/src/sgml/plperl.sgml index cff7a847dee..518a86459ad 100644 --- a/doc/src/sgml/plperl.sgml +++ b/doc/src/sgml/plperl.sgml @@ -278,6 +278,20 @@ SELECT * FROM perl_row(); hash will be returned as null values. + + Similarly, output arguments of procedures can be returned as a hash + reference: + + +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); + + + PL/Perl functions can also return sets of either scalar or composite types. Usually you'll want to return rows one at a diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index c1e3c6a19d8..6c25116538a 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1870,6 +1870,22 @@ SELECT * FROM get_available_flightid(CURRENT_DATE); then NULL must be returned. Returning any other value will result in an error. + + + If a procedure has output parameters, then the output values can be + assigned to the parameters as if they were variables. For example: + +CREATE PROCEDURE triple(INOUT x int) +LANGUAGE plpgsql +AS $$ +BEGIN + x := x * 3; +END; +$$; + +CALL triple(5); + + diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml index ba79beb7437..3b7974690ed 100644 --- a/doc/src/sgml/plpython.sgml +++ b/doc/src/sgml/plpython.sgml @@ -649,6 +649,17 @@ return (1, 2) $$ LANGUAGE plpythonu; SELECT * FROM multiout_simple(); + + + + + Output parameters of procedures are passed back the same way. For example: + +CREATE PROCEDURE python_triple(INOUT a integer, INOUT b integer) AS $$ +return (a * 3, b * 3) +$$ LANGUAGE plpythonu; + +CALL python_triple(5, 10); diff --git a/doc/src/sgml/pltcl.sgml b/doc/src/sgml/pltcl.sgml index a834ab8862b..01f6207d363 100644 --- a/doc/src/sgml/pltcl.sgml +++ b/doc/src/sgml/pltcl.sgml @@ -186,6 +186,18 @@ $$ LANGUAGE pltcl; + + Output arguments of procedures are returned in the same way, for example: + + +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); + + + The result list can be made from an array representation of the diff --git a/doc/src/sgml/ref/call.sgml b/doc/src/sgml/ref/call.sgml index d45e3ec22e9..7418e19eeba 100644 --- a/doc/src/sgml/ref/call.sgml +++ b/doc/src/sgml/ref/call.sgml @@ -31,6 +31,10 @@ CALL name ( [