Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 766825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:06:37+00:00 2026-05-14T17:06:37+00:00

rails 2.3.4, sqlite3 I’m trying this Production.find(:all, :conditions => ["time > ?", start_time.utc], :order

  • 0

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?


UPDATE/SOLVED:
time is a reserved sqlite3 keyword (date, amongst others, is too). This is why :order => 'time DESC' works in PostgreSQL (non-reserved keyword), but not in sqlite3. The solution is to avoid having sqlite3 keywords as column names if you ever intend to sort on them. Renaming solves the problem.

I’ve tested with the standard rails pattern updated_at and created_at, which works perfectly.

I still prefer sqlite3 in development, it’s so simple and smooth to work with, copy the database and send to your partner. Thanks to @newtover !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T17:06:38+00:00Added an answer on May 14, 2026 at 5:06 pm

    It is usually a bad idea to use reserved words without surrounding quotes. time is a built-in function in SQLite, try using the following instead and better get rid of the ambiguity in the first place:

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

    UPD: The problem seems to have appeared on SO:

    Rails Active Record find(:all, :order => ) issue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm using the rails plugin acts-as-taggable-on and I'm trying to find the top
So in rails I use sqlite3 for development and mysql for production. Sqlite3 and
I run rails new search in my console, and I get all of this:
I'm trying to use sqlite3 in my Rails 3 development environment instead of MySQL
I am trying to test insert a row into sqlite3 db, for the Rails
Trying to get Rails up on ubuntu, and I’m having trouble installing sqlite3-ruby –
OK, I've been using sqlite3 as development successfully for this tiny rails 3.1 project,
Running a rails site right now using SQLite3. About once every 500 requests or
What is a good .gitignore to use with Rails on Heroku? *.log *.sqlite3 what
I am running OS X 10.5, Ruby 1.8.6, Rails 2.1, sqlite3-ruby 1.2.2 and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.