SQLAlchemy, Psycopg2 and Postgresql COPY
accepted answer is correct but if you want more than just the EoghanM’s comment to go on the following worked for me in COPYing a table out to CSV… from sqlalchemy import sessionmaker, create_engine eng = create_engine(“postgresql://user:pwd@host:5432/db”) ses = sessionmaker(bind=engine) dbcopy_f = open(‘/tmp/some_table_copy.csv’,’wb’) copy_sql=”COPY some_table TO STDOUT WITH CSV HEADER” fake_conn = eng.raw_connection() fake_cur = … Read more