Skip to content

Instantly share code, notes, and snippets.

@AlexanderPavlenko
Last active December 12, 2015 03:28
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 AlexanderPavlenko/4706680 to your computer and use it in GitHub Desktop.
Save AlexanderPavlenko/4706680 to your computer and use it in GitHub Desktop.
fix PostgreSQL comparison of string and number
module Arel::Visitors
class ToSql
alias :visit_Fixnum :quoted
alias :visit_Bignum :quoted
end
end
module ActiveRecord::ConnectionAdapters
class PostgreSQLAdapter
module FixNumberToStringComparison
def quote(value, column)
if value.is_a?(Numeric) && column.type == :string
"'#{value}'"
else
super
end
end
end
include FixNumberToStringComparison
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment