On Fri, Jan 13, 2012 at 3:44 PM, Aaron Patterson
<[email protected]> wrote:
> It depends on the level of API people want to use.  For example, PG
> always returns strings.  That means we need to know the types for which
> we're querying.  Say someone does this against pg:
>
>  connection.execute 'select 1.2 + 20'
>
> we can't know to cast that to a float.

Actually, you can if you use the mysql, pg, postgres, and postgres-pr
drivers (and most other drivers that return strings for everything).
When you get the results of the query, you can query the metadata of
the results to get the types of the columns.  Sequel uses this
information to typecast such results correctly, and there is no reason
ActiveRecord couldn't do the same:

  irb(main):001:0> DB['SELECT 1'].single_value
  => 1
  irb(main):002:0> DB["SELECT '1'"].single_value
  => "1"
  irb(main):003:0> DB["SELECT 1.2"].single_value
  => #<BigDecimal:20e8334b0,'0.12E1',18(18)>
  irb(main):004:0> DB["SELECT 1.2::real"].single_value
  => 1.2

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