Output parameters are most useful when returning multiple values : Function Parameter « Store Procedure Function « PostgreSQL






Output parameters are most useful when returning multiple values


postgres=#
postgres=# -- Output parameters are most useful when returning multiple values
postgres=#
postgres=# CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$
postgres$# BEGIN
postgres$#    sum := x + y;
postgres$#    prod := x * y;
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=#
postgres=# select sum_n_product(1,2);
     REATE
 sum_n_product
---------------
 (3,2)
(1 row)

postgres=#
postgres=# drop function sum_n_product(x int, y int, OUT sum int, OUT prod int);
DROP FUNCTION
postgres=#
postgres=#
           
       








Related examples in the same category

1.Here the $1 references the value of the first function argument whenever the function is invoked
2.Pass constant to function
3.OUT parameter
4.Real number parameter
5.Two out parameters
6.'Anyelement' parameter
7.Pass in a whole row
8.Use defined data type as the function parameter