I wrote code that takes csv and export it to sql table. It looks like this:  def import_to_temp_table(table_name, filepath)    headers_with_type = headers_for_temp_table.map { |x| x + ' text' }.join(', ')    full_table_name = csv_temp_#{table_name}    conn = ActiveRecord::Base.connection_pool.checkout    raw = conn.raw_connection    conn_string = COPY #{full_table_name} FROM STDIN WITH DELIMITER ',' csv header;    conn.execute(DROP TABLE IF EXISTS #{full_table_name};)    create_table_string = CREATE TABLE #{full_table_name} ( id serial NOT NULL, CONSTRAINT #{full_table_name}_pk PRIMARY KEY (id),  + headers_with_type + );    conn.execute(create_table_string)    raw.copy_data conn_string do      File.open(filepath, 'r').each do |line|        raw.put_copy_data #{$INPUT_LINE_NUMBER - 1}, + line      end    end    conn.select_value(select count(*) from #{full_table_name}).to_i  endThis method will create table based on tablename variable, iterate thorugh csv headers and create columns with text type, and then will insert data to those columns. What do you think about this solution?
Copying csv to sql_table
ruby;sql;ruby on rails;csv;active record