Re: weirdness with the a sql update

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: weirdness with the a sql update
Дата
Msg-id 20050804143522.GA25982@svana.org
обсуждение исходный текст
Ответ на weirdness with the a sql update  (Tony Caduto <tony_caduto@amsoftwaredesign.com>)
Список pgsql-general
On Thu, Aug 04, 2005 at 09:19:44AM -0500, Tony Caduto wrote:
> Hi,
>
> I just noticed this, if I do a update like this:
>
> update new_requests set name = 'tony' where request_id = 2
>
> If I do a select * from new_requests that record I just updated is now
> at the bottom , before the update it was at the top?

Table in SQL don't have an implicit order. If you want the rows in a
particular order, you need to use ORDER BY.

> Why is Postgresql changing the ordering of the results after a simple
> update?

Because it's silly to order stuff if you didn't ask for a particular
order. Waste of CPU cycles.

> It almost looks like the record is being dropped and then readded to the
> end.

Under the hood, that's what happens. But it might appear at the end, in
the middle, anywhere. If want an order, use ORDER BY, otherwise it'll
be random.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: What happens when wal fails?
Следующее
От: Douglas McNaught
Дата:
Сообщение: Re: weirdness with the a sql update