diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-12-06 23:09:52 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-12-06 23:09:52 -0500 |
commit | 31a891857a128828d47d93c63e041f3b69cbab70 (patch) | |
tree | 742dc2b998ee50b7e97a45704c374fcb940485a3 /doc/src | |
parent | da07a1e856511dca59cbb1357616e26baa64428e (diff) | |
download | postgresql-31a891857a128828d47d93c63e041f3b69cbab70.tar.gz postgresql-31a891857a128828d47d93c63e041f3b69cbab70.zip |
Improve pl/pgsql to support composite-type expressions in RETURN.
For some reason lost in the mists of prehistory, RETURN was only coded to
allow a simple reference to a composite variable when the function's return
type is composite. Allow an expression instead, while preserving the
efficiency of the original code path in the case where the expression is
indeed just a composite variable's name. Likewise for RETURN NEXT.
As is true in various other places, the supplied expression must yield
exactly the number and data types of the required columns. There was some
discussion of relaxing that for pl/pgsql, but no consensus yet, so this
patch doesn't address that.
Asif Rehman, reviewed by Pavel Stehule
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/plpgsql.sgml | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 07fba57c0e1..b33c41e02ab 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1571,11 +1571,11 @@ RETURN <replaceable>expression</replaceable>; </para> <para> - When returning a scalar type, any expression can be used. The - expression's result will be automatically cast into the - function's return type as described for assignments. To return a - composite (row) value, you must write a record or row variable - as the <replaceable>expression</replaceable>. + In a function that returns a scalar type, the expression's result will + automatically be cast into the function's return type as described for + assignments. But to return a composite (row) value, you must write an + expression delivering exactly the requested column set. This may + require use of explicit casting. </para> <para> @@ -1600,6 +1600,20 @@ RETURN <replaceable>expression</replaceable>; however. In those cases a <command>RETURN</command> statement is automatically executed if the top-level block finishes. </para> + + <para> + Some examples: + +<programlisting> +-- functions returning a scalar type +RETURN 1 + 2; +RETURN scalar_var; + +-- functions returning a composite type +RETURN composite_type_var; +RETURN (1, 2, 'three'::text); -- must cast columns to correct types +</programlisting> + </para> </sect3> <sect3> |