Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created November 10, 2010 06:13
Show Gist options
  • Save teeparham/670438 to your computer and use it in GitHub Desktop.
Save teeparham/670438 to your computer and use it in GitHub Desktop.
sqlite sorts null values differently than postgres
# say we have a Monkey with a boolean column
create_table :monkeys do |t|
t.boolean :is_nice
end
Monkey.create()
Monkey.create(:is_nice => true)
Monkey.create(:is_nice => false)
# now we got 3 monkeys
# postgres:
Monkey.order(:is_nice).map &:is_nice
=> [false, true, nil]
# sqlite:
Monkey.order(:is_nice).map &:is_nice
=> [nil, false, true]
# Monkey business!!!
# next time do this:
create_table :monkeys do |t|
t.boolean :is_nice, :default => true
end
# or you can default to false if you like mean monkeys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment