Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4d67961

Browse files
committed
PL/pgSQL doc: Add example for RETURN QUERY
Erwin Brandstetter and Pavel Stěhule
1 parent0c1a160 commit4d67961

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)

[8]ページ先頭

©2009-2025 Movatter.jp