How to find the column type?


#1

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.


#2

Larry K. 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 S.
http://blog.hasmanythrough.com