Re: Counting bool flags in a complex query

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Counting bool flags in a complex query
Дата
Msg-id 24511.970808507@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] Counting bool flags in a complex query  (Michael Richards <miker@scifair.acadiau.ca>)
Список pgsql-hackers
Quite awhile ago, Michael Richards <miker@scifair.acadiau.ca> wrote:
> It looks like the order by is only being applied to the original select,
> not the unioned select. Some authority should check on it, but by thought
> it that a union does not necessarily maintain the order, so the entire
> select should be applied to the order.

Just FYI, I have committed code for 7.1 that allows ORDER BY to work
correctly for a UNION'd query.  A limitation is that you can only do
ordering on columns that are outputs of the UNION:

regression=# select q1 from int8_tbl union select q2 from int8_tbl order by 1;       q1
--------------------4567890123456789              123              456 4567890123456789
(4 rows)

regression=# select q1 from int8_tbl union select q2 from int8_tbl order by int8_tbl.q1+1;
ERROR:  ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns

In the general case of an arbitrary ORDER BY expression, it's not clear
how to transpose it into each UNION source select anyway.  It could
be made to work for expressions using only the output columns, but since
ORDER BY expressions are not standard SQL I'm not in a big hurry to make
that happen...
        regards, tom lane


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

Предыдущее
От: Philip Warner
Дата:
Сообщение: Re: ALTER TABLE DROP COLUMN
Следующее
От: Kristofer Munn
Дата:
Сообщение: Exited with status 139