mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
Implement SQL-spec RETURNS TABLE syntax for functions.
(Unlike the original submission, this patch treats TABLE output parameters as being entirely equivalent to OUT parameters -- tgl) Pavel Stehule
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.132 2008/07/16 01:30:21 tgl Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.133 2008/07/18 03:32:51 tgl Exp $ -->
|
||||
|
||||
<chapter id="plpgsql">
|
||||
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
|
||||
@@ -157,6 +157,8 @@
|
||||
parameters in place of an explicit specification of the return type.
|
||||
This does not add any fundamental capability to the language, but
|
||||
it is often convenient, especially for returning multiple values.
|
||||
The <literal>RETURNS TABLE</> notation can also be used in place
|
||||
of <literal>RETURNS SETOF</>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -468,6 +470,23 @@ $$ LANGUAGE plpgsql;
|
||||
<literal>RETURNS record</>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Another way to declare a <application>PL/pgSQL</application> function
|
||||
is with <literal>RETURNS TABLE</>, for example:
|
||||
|
||||
<programlisting>
|
||||
CREATE FUNCTION extended_sales(p_itemno int) RETURNS TABLE(quantity int, total numeric) AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT quantity, quantity * price FROM sales WHERE itemno = p_itemno;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
</programlisting>
|
||||
|
||||
This is exactly equivalent to declaring one or more <literal>OUT</>
|
||||
parameters and specifying <literal>RETURNS SETOF
|
||||
<replaceable>sometype</></literal>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
When the return type of a <application>PL/pgSQL</application>
|
||||
function is declared as a polymorphic type (<type>anyelement</type>,
|
||||
|
||||
Reference in New Issue
Block a user