Permalink
Browse files

Cast number to string in Postgres

fixes #9170
  • Loading branch information...
1 parent d25a822 commit aae89ee8607a802557b4877feb995204e0b58fed @lukaszx0 lukaszx0 committed Mar 12, 2013
View
9 activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -51,9 +51,12 @@ def quote(value, column = nil) #:nodoc:
super
end
when Numeric
- return super unless column.sql_type == 'money'
- # Not truly string input, so doesn't require (or allow) escape string syntax.
- "'#{value}'"
+ if column.sql_type == 'money' || [:string, :text].include?(column.type)
+ # Not truly string input, so doesn't require (or allow) escape string syntax.
+ "'#{value}'"
+ else
+ super
+ end
when String
case column.sql_type
when 'bytea' then "'#{escape_bytea(value)}'"
View
8 activerecord/test/cases/adapters/postgresql/quoting_test.rb
@@ -44,6 +44,14 @@ def test_quote_float_infinity
c = Column.new(nil, 1, 'float')
assert_equal "'Infinity'", @conn.quote(infinity, c)
end
+
+ def test_quote_cast_numeric
+ fixnum = 666
+ c = Column.new(nil, nil, 'string')
+ assert_equal "'666'", @conn.quote(fixnum, c)
+ c = Column.new(nil, nil, 'text')
+ assert_equal "'666'", @conn.quote(fixnum, c)
+ end
end
end
end

0 comments on commit aae89ee

Please sign in to comment.