So, I have a DB field zip\_code which is a string. Then I attempted to compare this string field with integers that I input (just to see what happens), and all sorts of strange things started to happen:

All the assertions here will be true:

```
User.destroy_all
User.create!(zip_code: "0056") # zip_code is a string in the schema.rb
User.create!(zip_code: "0473")
User.create!(zip_code: "5")
assert_equal 3, User.all.count

assert_equal 0, User.where('zip_code = 0').count 
# "SELECT \"users\".* FROM \"users\"  WHERE (zip_code = 0)"

assert_equal 3, User.where('zip_code > 0').count
# "SELECT \"users\".* FROM \"users\"  WHERE (zip_code > 0)"

assert_equal 2, User.where('zip_code < 1').count
# "SELECT \"users\".* FROM \"users\"  WHERE (zip_code < 1)"
# ["0056", "0473"]
# Question 1: So is "0056" and "0473" interpreted as 0 with decimals? Why are they interpreted as between 0 and 1?

assert_equal 2, User.where('zip_code >= 0 AND zip_code <= 20000').count
# "SELECT \"users\".* FROM \"users\"  WHERE (zip_code >= 0 AND zip_code <= 20000)"
# ["0056", "0473"]
# Question 2: Why isn't the user with zip_code "5" included here?

assert_equal 0, User.where('zip_code >= 1 AND zip_code <= 20000').count
# "SELECT \"users\".* FROM \"users\"  WHERE (zip_code >= 1 AND zip_code <= 20000)"
# []
# Question 3: Why is none of the users found here?

assert_equal 2, User.where(zip_code: 0..20000).count
# "SELECT \"users\".* FROM \"users\"  WHERE (\"users\".\"zip_code\" BETWEEN 0 AND 20000)"
# ["0056", "0473"]
# Question 4: Why isn't the user with zip_code "5" included here?

assert_equal 0, User.where(zip_code: 1..20000).count
# "SELECT \"users\".* FROM \"users\"  WHERE (\"users\".\"zip_code\" BETWEEN 1 AND 20000)"
# []
# Question 5: Why is none of the users found here?

```

Why? Can someone explain this behavior? What is it about the comparison between string and integer in the SQL DB that is causing this behavior?

For the record: I am using SQLite, Rails 4.1.16, and ruby 2.3.1p112 in these tests.