Guest User

Untitled

a guest
Sep 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #!/usr/bin/env/python
  2.  
  3. import psycopg2
  4.  
  5. # Get a database connection
  6. dsn = "dbname=%s user=%s password=%s host=%s port=%s" % ('db_name','username','password','remote_host_ip','port')
  7. conn = psycopg2.connect(dsn)
  8.  
  9. query = "COPY public.hiringpattern_new FROM stdin WITH CSV HEADER DELIMITER as ',' "
  10. cur = conn.cursor()
  11. with open('csv_file_path', 'r') as f:
  12. cur.copy_expert(sql=copy_sql, file=f)
  13. conn.commit()
  14. cur.close()
Add Comment
Please, Sign In to add comment