Created
November 10, 2010 06:13
-
-
Save teeparham/670438 to your computer and use it in GitHub Desktop.
sqlite sorts null values differently than postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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