diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml
index 3b2b49d..9e61a20 100644
--- a/doc/src/sgml/plpgsql.sgml
+++ b/doc/src/sgml/plpgsql.sgml
@@ -1733,6 +1733,38 @@ SELECT * FROM get_all_foo();
        increasing this parameter.
       </para>
      </note>
+
+     <para>
+      Here is an example of a function using <command>RETURN
+      QUERY</command>:
+
+<programlisting>
+CREATE FUNCTION get_available_flightid(date) RETURNS SETOF integerAS
+$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 raise exception
+-- if there are not available flight.
+SELECT * FROM get_available_flightid(CURRENT_DATE);
+
+</programlisting>
+
+     </para>
     </sect3>
    </sect2>
 
