Skip site navigation (1) Skip section navigation (2)

Re: After updating dataset the record goes to the end of the dataset

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: After updating dataset the record goes to the end of the dataset
Date: 2008-04-22 10:11:42
Message-ID: fukdku$6qa$1@ger.gmane.org (view raw or flat)
Thread:
Lists: pgsql-sql
Nacef LABIDI, 22.04.2008 11:54:
> Hi all,
> 
> I am using Postgres in a Delphi application through ODBC. I am having an 
> issue with updating records.
> 
> When I create a dataset to get the records in a table then after I 
> update one of these records and then refresh the dataset, the record 
> goes to the end of the dataset. This is disappointing when editing 
> records on a DBGrid, where users find their updated records jump to the 
> end of the grid. Even after restarting the application, the updated 
> record keeps showing at the end of the grid. I have tried the same thing 
> with SQL Server and it works normally, so I thought it was a postgres 
> behvior.
> 
> Has anyone an idea about what could be the cause of such a behavior.

Rows in a relational database are not sorted. This is true for any RDBMS.

If you want to apply a certain sort order you *have* to use an ORDER BY clause for your SELECT. 
If the rows show up in the order you "expect" without an ORDER BY this is pure coincidence (even with SQL Server)

The simply solution is to add an ORDER BY that sorts e.g. by a timestamp that is set when the row is created.

Regards
Thomas


In response to

pgsql-sql by date

Next:From: Gurjeet SinghDate: 2008-04-22 10:12:37
Subject: Re: After updating dataset the record goes to the end of the dataset
Previous:From: Nacef LABIDIDate: 2008-04-22 10:10:41
Subject: Re: After updating dataset the record goes to the end of the dataset

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group