From: Josh Berkus <josh@agliodbs.com>
To: A.M. <agentm@cmu.edu>
To: pgsql-sql@postgresql.org
Subject: Re: UNION and ORDER BY ... IS NULL ASC
Date: Fri, 4 Apr 2003 18:52:30 -0800
Message-ID: <200304041852.30121.josh@agliodbs.com> (raw)
In-Reply-To: <1E4E6631-670A-11D7-89FA-0030657192DA@cmu.edu>
References: <1E4E6631-670A-11D7-89FA-0030657192DA@cmu.edu>
AM,
> CREATE TABLE test(a int);
> SELECT a FROM test UNION SELECT a FROM test ORDER BY a IS NULL ASC;
>
> returns:
>
> ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of
> the result columns
I do believe that this is per the SQL spec; UNIONs may only be sorted on the
output columns.
So if you did
SELECT a, (a IS NULL) as test_a
FROM test
UNION
SELECT a, (a IS NULL)
FROM test2
ORDER BY test_a
... it should work.
--
-Josh Berkus
Aglio Database Solutions
San Francisco
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, agentm@cmu.edu
Subject: Re: UNION and ORDER BY ... IS NULL ASC
In-Reply-To: <200304041852.30121.josh@agliodbs.com>
* 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