Forum: Ruby on Rails ActiveRecord Postgres small inconsistency

Posted by rahajiyev@bankofbaku.com (Guest)
on 2012-05-07 17:04
(Received via mailing list)
Hi, I'm using Rails 3.2.1 and following through Mike Hartl's
tutorial.

irb(main):024:0> User.first
  User Load (0.6ms)  SELECT "users".* FROM "users" LIMIT 1
=> ...
irb(main):025:0> User.last
  User Load (1.0ms)  SELECT "users".* FROM "users" ORDER BY
"users"."id" DESC LIMIT 1
=> ...

Here's what PostgreSQL docs say concerning ORDER-less SELECTs:
"If the ORDER BY clause is specified, the returned rows are sorted in
the specified order. If ORDER BY is not given, the rows are returned
in whatever order the system finds fastest to produce. (See ORDER BY
Clause below.)"


So, shouldn't ORDER BY .. ASC be specified explicitly, instead of
relying on an implementation detail that might later change?

Thanks.
Posted by Jeremy Walker (Guest)
on 2012-05-07 18:37
(Received via mailing list)
On 7 May 2012 08:31, rahajiyev@bankofbaku.com 
<rahajiyev@bankofbaku.com>wrote:

>
> Here's what PostgreSQL docs say concerning ORDER-less SELECTs:
> "If the ORDER BY clause is specified, the returned rows are sorted in
> the specified order. If ORDER BY is not given, the rows are returned
> in whatever order the system finds fastest to produce. (See ORDER BY
> Clause below.)"
>
>
> So, shouldn't ORDER BY .. ASC be specified explicitly, instead of
> relying on an implementation detail that might later change?
>

This strikes me as a good suggestion. I'll put a pull request together 
for
it unless anyone has any objections.

Jeremy Walker
http://www.ihid.co.uk
Posted by Jeremy Walker (Guest)
on 2012-05-07 18:54
(Received via mailing list)
On 7 May 2012 17:34, Jeremy Walker <jez.walker@gmail.com> wrote:

>> irb(main):025:0> User.last
>>
>> So, shouldn't ORDER BY .. ASC be specified explicitly, instead of
>> relying on an implementation detail that might later change?
>>
>
> This strikes me as a good suggestion. I'll put a pull request together for
> it unless anyone has any objections.
>

After a quick browse through the code, this has already been added to 
Rails
master and will appear in a future release.
Posted by Raphael Costa (raphaelwc)
on 2012-08-27 14:01
(Received via mailing list)
Could you please send the link of this commit?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.