aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2013-04-23 22:46:36 -0400
committerPeter Eisentraut <peter_e@gmx.net>2013-04-24 21:54:46 -0400
commit4d67961110d17768021bac2c00fd395942d03170 (patch)
tree4d6bef46846304791036f7564ecbd658b7fe9e7a /doc/src
parent0c1a160a68b89f5b2c31eac458ca2d62a622a524 (diff)
downloadpostgresql-4d67961110d17768021bac2c00fd395942d03170.tar.gz
postgresql-4d67961110d17768021bac2c00fd395942d03170.zip
PL/pgSQL doc: Add example for RETURN QUERY
Erwin Brandstetter and Pavel Stěhule
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/plpgsql.sgml30
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml
index 3b2b49d09be..dbea3cd2803 100644
--- a/doc/src/sgml/plpgsql.sgml
+++ b/doc/src/sgml/plpgsql.sgml
@@ -1714,6 +1714,36 @@ SELECT * FROM get_all_foo();
</programlisting>
</para>
+ <para>
+ Here is an example of a function using <command>RETURN
+ QUERY</command>:
+
+<programlisting>
+CREATE FUNCTION get_available_flightid(date) RETURNS SETOF integer AS
+$BODY$
+BEGIN
+ RETURN QUERY SELECT flightid
+ FROM flight
+ WHERE flightdate >= $1
+ AND flightdate < ($1 + 1);
+
+ -- Since execution is not finished, we can check whether rows were returned
+ -- and raise exception if not.
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'No flight at %.', $1;
+ END IF;
+
+ RETURN;
+ END
+$BODY$
+LANGUAGE plpgsql;
+
+-- Returns available flights or raises exception if there are no
+-- available flights.
+SELECT * FROM get_available_flightid(CURRENT_DATE);
+</programlisting>
+ </para>
+
<note>
<para>
The current implementation of <command>RETURN NEXT</command>