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

Re: Inverted result set, why?

From: Joachim Achtzehnter <joachim(at)kraut(dot)bc(dot)ca>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Inverted result set, why?
Date: 2000-06-29 15:01:04
Message-ID: Pine.WNT.4.21.0006290752320.200-100000@van4 (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
On Tue, 27 Jun 2000 jeam(at)themail(dot)com wrote:
> I SELECT * and the records are retrieved in the order I inserted them,
> and that's correct.

Any order is correct because the order in which rows are returned for an
SQL query is completely unspecified unless your query uses the 'order by'

> However, if I SELECT the records from a Delphi 5 application, using
> the BDE and the latest ODBC driver, the result set is inverted, i.e.,
> on the same index key, the last record I inserted is listed first and
> so on.

Nothing wrong with this.

> This forces me to use an index even for tables I don't need one. Or
> worse yet, I need to create a second, auxiliary field on the table and
> add it to the index when I have one in order to get the proper order
> of the inserted records.

Even if you do all these things you still have no guarantee that rows are
returned in any particular order. Indexes may result in more efficient
retrieval or sorting but by themselves don't force any order on the
result. The fact that some implementation, or even several
implementations, return rows in a certain order (with or without indices)
does not imply that other implementations or future versions of the same
database will do the same.

> I don't know if I should blame Borland's BDE or the ODBC driver.

You can't blame them because they are not in violation of the SQL
specification. Use an 'order by' clause and you get the desired


In response to

pgsql-interfaces by date

Next:From: DnesbittDate: 2000-06-29 22:48:56
Subject: RE: JDBC Driver support for SQLException.getSQLState ()
Previous:From: grzegorz.przezdzieckiDate: 2000-06-29 11:48:25
Subject: PHP4 Postgresql *.dll

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