Re: [RFE] auto ORDER BY for SELECT

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Chris Angelico <rosuav(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [RFE] auto ORDER BY for SELECT
Date: 2012-01-24 09:42:15
Message-ID: CAF-3MvPOj5mLzQ+GoM7TXMfuO8+=w=pNUNmLzNeuoMn35Q4DNw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 24 January 2012 09:29, Chris Angelico <rosuav(at)gmail(dot)com> wrote:
> On Mon, Jan 23, 2012 at 11:17 PM, Douglas Eric <sekkuar(at)hotmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2012-01-24 10:47:59 Re: Best way to create unique primary keys across schemas?
Previous Message Chris Angelico 2012-01-24 08:29:27 Re: [RFE] auto ORDER BY for SELECT