Skip to content

Instantly share code, notes, and snippets.

@devkinoti
Created August 14, 2019 09:02
Show Gist options
  • Save devkinoti/8a8e73484355bd954f58e181c2b37292 to your computer and use it in GitHub Desktop.
Save devkinoti/8a8e73484355bd954f58e181c2b37292 to your computer and use it in GitHub Desktop.
def self.import(file)
conn = ActiveRecord::Base.connection
rc = conn.raw_connection
rc.exec("COPY callers (your_attributes) FROM STDIN WITH CSV")
file = File.open("#{file.path}", 'r')
while !file.eof?
rc.put_copy_data(file.readline)
end
rc.put_copy_end
while res = rc.get_result
if e_message = res.error_message
p e_message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment