From: | "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net> |
---|---|
To: | "James B(dot) Byrne" <byrnejb(at)harte-lyne(dot)ca> |
Cc: | Eric Hu <eric(at)lemurheavy(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to handle bogus nulls from ActiveRecord |
Date: | 2011-05-13 15:50:10 |
Message-ID: | BANLkTinpw5Fm7e+B3SZdPHQUFK7JMoUHfQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2011/5/13 James B. Byrne <byrnejb(at)harte-lyne(dot)ca>:
> Actually, it turn out that 'infinity' is supported in Ruby.
> Apparently infinity can be represented by assigning the value
> obtained by dividing a float by zero.
>
> $ irb
> ruby-1.8.7-p334 :001 > infinity = 1.0/0
> => Infinity
> ruby-1.8.7-p334 :002 > ninfinity = -1.0/0
> => -Infinity
> ruby-1.8.7-p334 :003 >
>
> So, I guess this now qualifies as a bug in the Ruby pg adapter gem.
humm.. interesting... i did some tests here...
[testdb]
SELECT * from infinity_date_test;
id | created_at
----+------------
1 | infinity
2 | infinity
3 | infinity
4 | infinity
5 | 2011-05-13
--- test.rb ---
require 'active_record'
ActiveRecord::Base.establish_connection({
:adapter => 'postgresql',
:database => 'testdb',
:port => 5434,
:host => 'localhost',
:username => 'guedes',
:password => 'guedes'
})
class InfinityDateTest < ActiveRecord::Base
set_table_name 'infinity_date_test'
end
InfinityDateTest.all.each do |row|
puts "#{row.id} | #{row.created_at} | #{row.created_at.class}"
end
i = InfinityDateTest.new
i.created_at = Date::Infinity.new
i.save
----
and the output
1 | | NilClass
2 | | NilClass
3 | | NilClass
4 | | NilClass
5 | 2011-05-13 | Date
/home/dba/.rvm/gems/ruby-1(dot)9(dot)2-p0(at)rails3/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:207:in
`rescue in log': PGError: ERRO: sintaxe de entrada é inválida para
tipo date: "--- !ruby/object:Date::Infinity
(ActiveRecord::StatementInvalid)
d: 1
"
LINE 1: ... INTO "infinity_date_test" ("created_at") VALUES ('--- !ruby...
^
: INSERT INTO "infinity_date_test" ("created_at") VALUES ('---
!ruby/object:Date::Infinity
d: 1
') RETURNING "id"
...
Well, fetching from database it came nil and when saved into, it was
trying to save a serialized object. From postgresql_adapter.rb [1] you
can see that it returns the correct internal type based when field
type is datetime, but i can't see the same thing for 'date', i suppose
that it going [2] to 'super' [3], so I suppose that this method [4]
should be override in 'postgresql_adapter.rb'.
[1] https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L85-86
[2] https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L117-118
[3] https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/column.rb#L253-254
[4] https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/column.rb#L197-219
Best regards,
--
Dickson S. Guedes
mail/xmpp: guedes(at)guedesoft(dot)net - skype: guediz
http://guedesoft.net - http://www.postgresql.org.br
From | Date | Subject | |
---|---|---|---|
Next Message | Nick Raj | 2011-05-13 16:09:58 | Re: Debug Contrib/cube code |
Previous Message | Tom Lane | 2011-05-13 14:29:59 | Re: pg_dumpall behavior in 9.1beta1 |