Answer the question
In order to leave comments, you need to log in
Psycopg2: Importing csv to postgres, how to do it?
Please tell me, I'm trying to import a csv file into a pg table. I am using psycopg2 and jupyter-notebook.
import psycopg2
conn = psycopg2.connect("host='localhost' port='5432' dbname='postgres' user='postgres' password='*******'")
cur = conn.cursor()
cur.execute("""truncate table "sandbox".promolist;""")
f = open(r'test.csv', 'r')
cur.copy_from(f, "sandbox.promolist", sep=';', null = "")
f.close()
conn.commit()
conn.close()
UndefinedTable
<ipython-input-2-149d5141a140> in <module>
4 cur.execute("""truncate table "sandbox".promolist;""")
5 f = open(r'test.csv', 'r')
----> 6 cur.copy_from(f, "sandbox.promolist", sep=';', null = "")
7 f.close()
8 conn.commit()
UndefinedTable: ОШИБКА: отношение "sandbox.promolist" не существует
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question