Skip to content

Instantly share code, notes, and snippets.

@titanous
Created June 14, 2011 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titanous/1025033 to your computer and use it in GitHub Desktop.
Save titanous/1025033 to your computer and use it in GitHub Desktop.
DEBUG -- : Test Load (0.2ms) SELECT "tests".* FROM "tests" ORDER BY COALESCE(updated_at DESC, created_at) ASC LIMIT 1
DEBUG -- : SQLite3::SQLException: near "DESC": syntax error: SELECT "tests".* FROM "tests" ORDER BY COALESCE(updated_at DESC, created_at) ASC LIMIT 1
/Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `log': SQLite3::SQLException: near "DESC": syntax error: SELECT "tests".* FROM "tests" ORDER BY COALESCE(updated_at DESC, created_at) ASC LIMIT 1 (ActiveRecord::StatementInvalid)
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/connection_adapters/sqlite_adapter.rb:135:in `execute'
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/connection_adapters/sqlite_adapter.rb:284:in `select'
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/base.rb:473:in `find_by_sql'
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/relation.rb:64:in `to_a'
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/relation/finder_methods.rb:349:in `find_last'
from /Users/titanous/.rvm/gems/ree-1.8.7-2011.03@fix/gems/activerecord-3.0.8/lib/active_record/relation/finder_methods.rb:136:in `last'
from order_by_coalesce.rb:15
require 'active_record'
require 'logger'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'data.sqlite3')
ActiveRecord::Schema.define :version => 0 do
create_table :tests, :force => true do |t|
t.timestamps
end
end
class Test < ActiveRecord::Base; end
Test.order('COALESCE(updated_at, created_at) DESC').last
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment