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

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: UNION and ORDER BY ... IS NULL ASC
Дата
Msg-id 200304041852.30121.josh@agliodbs.com
обсуждение исходный текст
Ответ на UNION and ORDER BY ... IS NULL ASC  ("A.M." <agentm@cmu.edu>)
Ответы Re: UNION and ORDER BY ... IS NULL ASC  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 BerkusAglio Database SolutionsSan Francisco



В списке pgsql-sql по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: UNION and ORDER BY ... IS NULL ASC
Следующее
От: Tom Lane
Дата:
Сообщение: Re: UNION and ORDER BY ... IS NULL ASC