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

From Douglas Eric
Subject [RFE] auto ORDER BY for SELECT
Date
Msg-id BLU166-W49985900AC6AEE6E60290DBF8A0@phx.gbl
Whole thread Raw
Responses Re: [RFE] auto ORDER BY for SELECT  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: [RFE] auto ORDER BY for SELECT  (Andreas Kretschmer <akretschmer@spamfence.net>)
Re: [RFE] auto ORDER BY for SELECT  ("David Johnston" <polobo@yahoo.com>)
Re: [RFE] auto ORDER BY for SELECT  (Chris Angelico <rosuav@gmail.com>)
List pgsql-general
I'm not sure if this is the right list to discuss this, but, I have a suggestion:

ORDER BY clause, as defined in the SELECT documentation says:

"If ORDER BY is not given, the rows are returned in whatever order the system finds fastest to produce"

This order is usually not wanted, as it is not predictable. I believe many people would expect  the order of rows
returned in this case, to be ordered as the primary key of the table, or the same order the rows were inserted.

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.
The present behavior would still be used in case of queries without any primary key fields.

This would save a lot of repeated clauses "ORDER BY <table primary key>" 
that we have to add to every SELECT, even the most simple one
"SELECT * FROM <table>"
If we actually want the order of the rows to make any sense.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: update with from
Next
From: Roger Leigh
Date:
Subject: Re: Schema version control