From: James Edward Gray II Date: 2007-07-16T00:21:46+09:00 Subject: Re: faster_csv column type On Jul 15, 2007, at 6:44 AM, Hu Ma wrote: > Hello all, Hello. > I'm using faster_csv to import some csv formatted data to a database. > I'm using FasterCSV.foreach method to add all data but I came across > with a problem I don't know how to overcome. > > First I convert all csv data using the available converters (and also > adding some others) but before I insert the data to the database I > need > to know each column type in order to first create the table and then > insert the data. > > Does anyone know how to do this? Does this give you any fresh ideas? >> require "faster_csv" => true >> data = <<-END name,age James,31 Dana,21 END => "name,age\nJames,31\nDana,21\n" >> FCSV.parse(data, :headers => true, :converters => :numeric) do |row| ?> p row.inject({}) { |h, (k, v)| h.merge(k => v.class) } >> end {"name"=>String, "age"=>Fixnum} {"name"=>String, "age"=>Fixnum} => nil James Edward Gray II