Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. def self.import(file)
  2. conn = ActiveRecord::Base.connection
  3. rc = conn.raw_connection
  4. rc.exec("COPY callers (your_attributes) FROM STDIN WITH CSV")
  5.  
  6. file = File.open("#{file.path}", 'r')
  7. while !file.eof?
  8. rc.put_copy_data(file.readline)
  9. end
  10.  
  11. rc.put_copy_end
  12.  
  13. while res = rc.get_result
  14. if e_message = res.error_message
  15. p e_message
  16. end
  17. end
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement