Reputation: 580
I have two schema in PostgreSQL i.e public schema and Staging schema. Then from pandas dataframe I tried to create table in Staging schema, so I tried this method.
# establishing connection with database using sql alcemy
engine = create_engine('postgresql://postgres:root@localhost:5432/TestWarehouse')
sales_df_col.to_sql("Staging.tblsalesdata",engine)
Then instead of creating table in Staging schema, table name 'Staging.tblsaledata' was created in public schema. How can I create table 'tblsalesdata' into Staging schema from pandas?
Upvotes: 0
Views: 745
Reputation: 462
According to documentation: pandas.DataFrame.to_sql, you need to pass schema as a separate parameters.
Try:
sales_df_col.to_sql("tblsalesdata",engine, schema='Staging')
Upvotes: 1