Forum: Ruby on Rails How to find the column type?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ddc850a63a423c3ff963bdf3a097652f?d=identicon&s=25 Larry Kelly (ldk2005)
on 2006-06-06 17:04
(Received via mailing list)
Journal.column_names returns the names of the columns in a table.

How would I determine the type of a column?

I tried:  Journal.sql_types.    ( didn't work).

hints, please.
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-06-06 18:32
Larry Kelly wrote:
> Journal.column_names returns the names of the columns in a table.
>
> How would I determine the type of a column?

Journal.columns returns a collection of Column objects, each with a name
and a type (among other things). Type is a symbol Here's the case
statement class Column uses to cast SQL types to Ruby types, which is
pretty good documentation of the types and how they get used:

        case type
          when :integer       then Fixnum
          when :float         then Float
          when :datetime      then Time
          when :date          then Date
          when :timestamp     then Time
          when :time          then Time
          when :text, :string then String
          when :binary        then String
          when :boolean       then Object
        end

--
Josh Susser
http://blog.hasmanythrough.com
This topic is locked and can not be replied to.