Search Postgresql Archives

Re: weirdness with the a sql update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>   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.

Attachment: pgpv7t63eh2q4.pgp
Description: PGP signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux