Re: UNION and ORDER BY ... IS NULL ASC

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "A(dot)M(dot)" <agentm(at)cmu(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: UNION and ORDER BY ... IS NULL ASC
Date: 2003-04-05 02:52:30
Message-ID: 200304041852.30121.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-04-05 04:17:40 Re: UNION and ORDER BY ... IS NULL ASC
Previous Message Stephan Szabo 2003-04-05 02:49:31 Re: UNION and ORDER BY ... IS NULL ASC