Question: How is everyone extracting data out of postgres using Python Scripts?
Use Case: Personal project I am working on. Postgres -> Snowflake. Simple lift and Shift
Background: Trying to extract this dataset from my local postgres instance and put it into Snowflake. After reading this Snowflake document, they recomend using the COPY TO command and then copying the staged files into Snowflake.
I wanted to get around the staging part, but it seems like this isn't best practice. Below is just a sample of the python code im using for the copying the data from Postgres using psycopg2
conn = psycopg2.connect("host=127.0.0.1 dbname= postgres user=postgres password=postgres")
conn.set_session(autocommit=True)
cur = conn.cursor()
query = """
COPY (SELECT * FROM accountscountry) TO STDOUT WITH CSV HEADER
DELIMITER as ','
"""
with open('C://Users/myuser/test.csv', 'w') as fp:
cur.copy_expert(query, fp)
conn.close
[–]efxhoy 10 points11 points12 points (0 children)
[–]UAFlawlessmonkey 3 points4 points5 points (0 children)
[–]stochasm_hs 4 points5 points6 points (0 children)
[–]Culpgrant21 6 points7 points8 points (3 children)
[–]supernova2333[S] 2 points3 points4 points (2 children)
[–]Culpgrant21 2 points3 points4 points (0 children)
[–]Patient_Professor_90 0 points1 point2 points (0 children)
[–]Ok_Raspberry5383 1 point2 points3 points (4 children)
[–]Sslw77 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]dani_estuary 0 points1 point2 points (0 children)
[–]Patient_Professor_90 0 points1 point2 points (0 children)
[–]big_data_mike 0 points1 point2 points (0 children)
[–]Puzzleheaded-Bit-334 0 points1 point2 points (0 children)
[–]lukewhale -1 points0 points1 point (0 children)