-
-
Save encryptblockr/738c528753c95189361ec534c0bdb903 to your computer and use it in GitHub Desktop.
This script can be used to copy a CSV file (with header) to a Postgres remote database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env/python | |
import psycopg2 | |
# Get a database connection | |
dsn = "dbname=%s user=%s password=%s host=%s port=%s" % ('db_name','username','password','remote_host_ip','port') | |
conn = psycopg2.connect(dsn) | |
query = "COPY public.hiringpattern_new FROM stdin WITH CSV HEADER DELIMITER as ',' " | |
fp = open('csv_file_path', 'r') | |
cur = conn.cursor() | |
cur.copy_expert(sql=query, file=fp) | |
conn.commit() | |
cur.close() | |
fp.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment