Re: ADD TO UPDATE LIMIT

Поиск
Список
Период
Сортировка
От Christophe Pettus
Тема Re: ADD TO UPDATE LIMIT
Дата
Msg-id 6E2FB117-52FA-44E4-B72D-B043163205A0@thebuild.com
обсуждение исходный текст
Ответ на ADD TO UPDATE LIMIT  (Andrey Furs <aefurs93@gmail.com>)
Список pgsql-bugs

> On Oct 23, 2020, at 09:36, Andrey Furs <aefurs93@gmail.com> wrote:
>
> Hi there!
> Are you serious !?
> Postgresql not UPDATE LIMIT !?
>
> UPDATE table SET id=100 WHERE id<1000 LIMIT 1;
>
> OMG!

What does that even mean, though?  There's no guarantee as to which row is going to be updated, even if that syntax
worked. LIMIT without an ORDER BY is not statistically random enough to be useful for true randomness, but is not
definedenough to be safe.  What you probably want is: 

    UPDATE t SET id=100 WHERE id = ( SELECT id FROM t ORDER BY id LIMIT 1);

--
-- Christophe Pettus
   xof@thebuild.com




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

Предыдущее
От: Andrey Furs
Дата:
Сообщение: ADD TO UPDATE LIMIT
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: ADD TO UPDATE LIMIT