Has anybody had to use the postgres COPY FROM STDIN to work with
Active Record. I have been googling around and have seen several posts
that supposedly do the trick but it doesn't work with rails 3.2 and
postgres 9.1 This is what I have so far. It runs without error but it
doesn't put any data in the table and doesn't log to the table.
conn = ActiveRecord::Base.connection_pool.checkout
conn.transaction do
rc = conn.raw_connection
rc.exec "TRUNCATE TABLE #{table_name};" if options[:truncate]
sql = "COPY #{table_name} (#{field_list.join(',')}) FROM STDIN
#{sql_parameters} "
p sql
rc.exec(sql)
if method == 1
rc.put_copy_data text + "\\.\n"
else
text.each_line { |line| rc.put_copy_data(line) }
end
rc.put_copy_end
#flush it..
while res = rc.get_result do
end
# ;
#end # very important to do this after a copy
puts "end"
end
ActiveRecord::Base.connection_pool.checkin(conn)
--
You received this message because you are subscribed to the Google Groups
"WellRailed" 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/wellrailed?hl=en.