Re: Support for Limit in Update, Insert...

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Support for Limit in Update, Insert...
Дата
Msg-id 28935.1126234165@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Support for Limit in Update, Insert...  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Ответы Re: Support for Limit in Update, Insert...  (Csaba Nagy <nagy@ecircle-ag.com>)
Re: Support for Limit in Update, Insert...  ("Jim C. Nasby" <jnasby@pervasive.com>)
Список pgsql-general
Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> This has been discussed before, and rejected.  Please see the archives.

For SELECT, both LIMIT and OFFSET are only well-defined in the presence
of an ORDER BY clause.  (One could argue that we should reject them when
no ORDER BY, but given that the database isn't getting changed as a side
effect, that's probably too anal-retentive.  When the database *is*
going to be changed, however, I for one like well-defined results.)

If this proposal included adding an ORDER BY to UPDATE/DELETE, then it
would at least be logically consistent.  I have not seen the use-case
for it though.  In any case you can usually get the equivalent result
with something like

    UPDATE foo SET ...
    WHERE pkey IN (SELECT pkey FROM foo ORDER BY ... LIMIT ...);

            regards, tom lane

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

Предыдущее
От: Leonid Safronie
Дата:
Сообщение: Cost based SELECT/UPDATE
Следующее
От: Poul Jensen
Дата:
Сообщение: SQL - planet redundant data