Re: 'order by' in an insert into command

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: 'order by' in an insert into command
Дата
Msg-id 21772.1094664797@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: 'order by' in an insert into command  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
Richard Huxton <dev@archonet.com> writes:
> In your example, I would expect the nextval() to be called during the
> "fetch", before the ordering. You could probably do something like:

> INSERT INTO pending_tnmt_sec
> SELECT foo.*, nextval('sec_seq') FROM
>    (
>      SELECT tseceventid, ...
>      ORDER BY tsecrtddt,tseceventid,tsecsecno
>    ) AS foo
> ;

> I'm not sure whether the SQL standard requires the ORDER BY to be
> processed in the sub-select. From a relational viewpoint, I suppose you
> could argue that ordering is strictly an output feature.

I believe the SQL standard disallows this entirely, precisely because it
considers ordering to be strictly an output feature.  Postgres will take
it though (in recent releases), and should produce the results Mike wants.

            regards, tom lane

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

Предыдущее
От: Oliver Elphick
Дата:
Сообщение: Re: Heritage
Следующее
От: Paul Thomas
Дата:
Сообщение: Re: Need Help in interface..