File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1714,6 +1714,36 @@ SELECT * FROM get_all_foo();
1714
1714
</programlisting>
1715
1715
</para>
1716
1716
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
+
1717
1747
<note>
1718
1748
<para>
1719
1749
The current implementation of <command>RETURN NEXT</command>
You can’t perform that action at this time.
0 commit comments