Skip to content

Commit 4d67961

Browse files
committed
PL/pgSQL doc: Add example for RETURN QUERY
Erwin Brandstetter and Pavel Stěhule
1 parent 0c1a160 commit 4d67961

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

doc/src/sgml/plpgsql.sgml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,36 @@ SELECT * FROM get_all_foo();
17141714
</programlisting>
17151715
</para>
17161716

1717+
<para>
1718+
Here is an example of a function using <command>RETURN
1719+
QUERY</command>:
1720+
1721+
<programlisting>
1722+
CREATE FUNCTION get_available_flightid(date) RETURNS SETOF integer AS
1723+
$BODY$
1724+
BEGIN
1725+
RETURN QUERY SELECT flightid
1726+
FROM flight
1727+
WHERE flightdate >= $1
1728+
AND flightdate < ($1 + 1);
1729+
1730+
-- Since execution is not finished, we can check whether rows were returned
1731+
-- and raise exception if not.
1732+
IF NOT FOUND THEN
1733+
RAISE EXCEPTION 'No flight at %.', $1;
1734+
END IF;
1735+
1736+
RETURN;
1737+
END
1738+
$BODY$
1739+
LANGUAGE plpgsql;
1740+
1741+
-- Returns available flights or raises exception if there are no
1742+
-- available flights.
1743+
SELECT * FROM get_available_flightid(CURRENT_DATE);
1744+
</programlisting>
1745+
</para>
1746+
17171747
<note>
17181748
<para>
17191749
The current implementation of <command>RETURN NEXT</command>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy