Re: [RFE] auto ORDER BY for SELECT - Mailing list pgsql-general

From Alban Hertroys
Subject Re: [RFE] auto ORDER BY for SELECT
Date
Msg-id CAF-3MvPOj5mLzQ+GoM7TXMfuO8+=w=pNUNmLzNeuoMn35Q4DNw@mail.gmail.com
Whole thread Raw
In response to Re: [RFE] auto ORDER BY for SELECT  (Chris Angelico <rosuav@gmail.com>)
List pgsql-general
On 24 January 2012 09:29, Chris Angelico <rosuav@gmail.com> wrote:
> On Mon, Jan 23, 2012 at 11:17 PM, Douglas Eric <sekkuar@hotmail.com> wrote:
>> I suggest to change this behavior. If one makes a SELECT statement without
>> any ORDER BY, it would be
>> clever to automatically sort by the first primary key found in the query, if
>> any.

I recently submitted a problem report with a product that had that
behaviour. The data involved was a table of database ID's and text
labels for use in a drop-down list. In such cases, sorting the data by
primary key (the ID) is rarely what you want!

For example, if you have a listing of car brands, sorting them by some
arbitrary ID quickly makes such a list impossible to use. You want
such a list sorted alphabetically. Defaulting to sorting by ID (like
aforementioned product did) does not make sense in such a case.

So, this is not just a bad idea from a performance perspective, it's
also often not what you want.

Of course specifying a "different" sort order than the default one
would solve the issue, but that's not the point here.
--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

pgsql-general by date:

Previous
From: Florian Weimer
Date:
Subject: Re: Incomplete startup packet help needed
Next
From: panam
Date:
Subject: Re: Best way to create unique primary keys across schemas?