From aac40bcc07b3defb2134b2c08a88e197c469a702 Mon Sep 17 00:00:00 2001 From: Innokenty Mihailov Date: Wed, 18 Dec 2013 23:12:53 +0200 Subject: pg, fix Infinity and NaN values conversion. Before this patch `Infinity`, `-Infinity` and `Nan` were read as `0`. --- .../lib/active_record/connection_adapters/postgresql/oid.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 540b3694b5..14beb7bd25 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -249,9 +249,14 @@ This is not reliable and will be removed in the future. def type; :float end def type_cast(value) - return if value.nil? - - value.to_f + case value + when nil; nil + when 'Infinity'; ::Float::INFINITY + when '-Infinity'; -::Float::INFINITY + when 'NaN'; ::Float::NAN + else + value.to_f + end end end -- cgit v1.2.3