From: K. Ari Krupnikov <ari@iln.net>
To: pgsql-sql@postgresql.org
Subject: ORDER BY in SQL functions
Date: Fri, 09 Feb 2001 20:16:13 -0500
Message-ID: <3A84965D.44806521@iln.net> (raw)
Are ORDER BYs allowed in SQL functions? Or do SQL functions work like
views that are as unordered as their underlting tables?
CREATE FUNCTION foo (INT)
RETURNS SETOF INT AS '
SELECT id
FROM table
WHERE some_colunm > $1
' LANGUAGE 'sql';
works. But if I try
CREATE FUNCTION foo (INT)
RETURNS SETOF INT AS '
SELECT id
FROM table
WHERE some_colunm > $1
ORDER BY some_other_colunm
' LANGUAGE 'sql';
the parser comes back with
ERROR: function declared to return int4 returns multiple values in
final retrieve
The sorting must occur in the function, because once I have a set of
IDs, there is no way to order them by some_other_column.
The function cannot be rewritten in pl/pgsql because it may return more
than one value.
--
K. Ari Krupnikov
DBDOM - bridging XML and relational databases
http://www.iter.co.il
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: ari@iln.net
Subject: Re: ORDER BY in SQL functions
In-Reply-To: <3A84965D.44806521@iln.net>
References: <3A84965D.44806521@iln.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox