Copy Data From Csv To Postgresql Using Python
Answer : Use the copy_from cursor method f = open(r'C:\Users\n\Desktop\data.csv', 'r') cur.copy_from(f, temp_unicommerce_status, sep=',') f.close() The file must be passed as an object. Since you are coping from a csv file it is necessary to specify the separator as the default is a tab character The way I solved this problem particular to use psychopg2 cursor class function copy_expert (Docs: http://initd.org/psycopg/docs/cursor.html). copy_expert allows you to use STDIN therefore bypassing the need to issue a superuser privilege for the postgres user. Your access to the file then depends on the client (linux/windows/mac) user's access to the file From Postgres COPY Docs (https://www.postgresql.org/docs/current/static/sql-copy.html): Do not confuse COPY with the psql instruction \copy. \copy invokes COPY FROM STDIN or COPY TO STDOUT, and then fetches/stores the data in a file accessible to the psql client. Thus, file accessibility and access ri...