@@ -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>