Active Record Postgresql handling of Dates

I am trying to convert one db to Active Record based objects, so I read
in the rows from the old db, create an AR object, then do o.save.

Both dbs are postgres. One of the fields is a date field.

When I read it from the old table with dbi, the system recognizes it as
a date field and contructs a Date object. But when I assign the object
to an attribute in the AR object, then do o.save, I get this error
message:

···

====================================
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:462:in
`log': ERROR: invalid input syntax for type date: "---
!ruby/object:DBI::Date (ActiveRecord::StatementInvalid)
day: 23
month: 4
year: 2004"
: INSERT INTO owners ("city", "filed_on", "name", "zip", "middle",
"street1", "country", "last", "street2", "cik", "first", "is_entity",
"eolid", "hon", "stamp", "state", "suffix") VALUES('Oakland', '---
!ruby/object:DBI::Date
day: 23
month: 4
year: 2004', 'BERRIE ANGELICA', '07436', '', '40 Russ Berrie & Co Inc',
'United States', 'Berrie', '111 Bauer Drive', 1249690, 'Angelica', 'f',
NULL, '', NULL, 'NJ', '') from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/postgresql_adapter.rb:109:in
`execute'

It's the filed_on field that is causing the problems and the only Date
field in the record.

Anyone know what the problem is? My suspicion is that the postgres
adapter for AR is not able to cope with postgres 'date' fields, which
is puzzling for such a fundemental data type.

I would appreciate any help. I am new to Ruby and, of course, active
record.

Thanks.

This question would be better directed to the Rails mailing list:
http://lists.rubyonrails.org/mailman/listinfo/rails
http://news.gmane.org/gmane.comp.lang.ruby.rails

Cheers,
Ken

It constructs a DBI::Date object, not a Date object. Active Record has
no idea what a DBI::Date object is, nor how it relates to a date, so
it tries to save it by marshalling with YAML. I haven't used
DBI::Date, but if there is a #to_time method, use it before assigning
the attribute, otherwise you can do something like:
  owner.filed_on = Time.local(dbi_record.filed_on.year,
dbi_record.filed_on.month, ... )

Again, not sure of the API, but you should get the idea.

···

On 9/7/05, ded <ded-google@ddoherty.net> wrote:

I am trying to convert one db to Active Record based objects, so I read
in the rows from the old db, create an AR object, then do o.save.

Both dbs are postgres. One of the fields is a date field.

When I read it from the old table with dbi, the system recognizes it as
a date field and contructs a Date object. But when I assign the object
to an attribute in the AR object, then do o.save, I get this error
message:

--
David Naseby
http://homepages.ihug.com.au/~naseby/

Thanks, David. That gives me something to chew on.