On Tue, Jul 17, 2012 at 8:26 PM, Ken Collins <[email protected]> wrote:
>
> Is this a limitation of PostgreSQL or the ruby library that is used by said 
> adapter's #raw_connection? Specifically, computed column support? I know in 
> SQL Server that `MAX(datetime_column)` would return the proper datatype and 
> the low level connection ruby library, in this case TinyTDS, would do the 
> legwork before handing things to the adapter then ActiveRecord.
>
> Could the same be achieved doing a CAST() in your SQL string for the select?

It's not necessarily a limitation of the PostgreSQL ruby library.  pg,
postgres, and postgres-pr all return fields as ruby Strings, but make
the type oid metadata available for all returned fields (doesn't
matter if they are computed fields or not).  You shouldn't even need
an SQL cast (as max(timestamp_field) should be of type timestamp), you
just need to know how to map PostgreSQL type oids to ruby classes.
Sequel does this, and I've read that ActiveRecord 4 will as well (and
it looks like it does, see below).

Maybe what needs to be fixed is replies_topics.written_on is a
timestamptz field, and ActiveRecord currently treats that as a string
instead of a datetime value
(https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb#L228)

Jeremy

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to