Sqlite3 activerecord :order => "time DESC" doesn't sort

Posted by Ole Morten Amundsen on Stack Overflow See other posts from Stack Overflow or by Ole Morten Amundsen
Published on 2010-04-27T09:11:12Z Indexed on 2010/04/27 9:13 UTC
Read the original article Hit count: 278

Filed under:
|
|

rails 2.3.4, sqlite3

I'm trying this

Production.find(:all, :conditions => ["time > ?", start_time.utc], :order => "time DESC", :limit => 100)

The condition works perfectly, but I'm having problems with the :order => time DESC.

By chance, I discovered that it worked at Heroku (testing with heroku console), which runs PostgreSQL. However, locally, using sqlite3, new entries will be sorted after old ones, no matter what I set time to. Like this (output has been manually stripped): second entry is new:

Production id: 2053939460, time: "2010-04-24 23:00:04", created_at: "2010-04-24 23:00:05"

Production id: 2053939532, time: "2010-04-25 10:00:00", created_at: "2010-04-27 05:58:30"

Production id: 2053939461, time: "2010-04-25 00:00:04", created_at: "2010-04-25 00:00:04"

Production id: 2053939463, time: "2010-04-25 01:00:04", created_at: "2010-04-25 01:00:04"

Seems like it sorts on the primary key, id, not time. Note that the query works fine on heroku, returning a correctly ordered list! I like sqlite, it's so KISS, I hope you can help me...

Any suggestions?

© Stack Overflow or respective owner

Related posts about rails

Related posts about sqlite3