I am trying to write a pandas DataFrame to a PostgreSQL database, using a schema-qualified table.
I use the following code:
import pandas.io.sql as psql from sqlalchemy import create_engine engine = create_engine(r'postgresql://some:user@host/db') c = engine.connect() conn = c.connection df = psql.read_sql("SELECT * FROM xxx", con=conn) df.to_sql('a_schema.test', engine) conn.close() What happens is that pandas writes in schema "public", in a table named 'a_schema.test', instead of writing in the "test" table in the "a_schema" schema.
How can I instruct pandas to use a schema different than public?
Thanks
engine.connect(), you should just pass the engine toread_sql. Furthermore, the function is available in toplevel pandas, so no need to importpsqlfor that.