Include Schema in psycopg2 Connection String
Include Schema in psycopg2 Connection String
December 19, 2022
Info from https://stackoverflow.com/questions/59298580/how-to-specify-schema-in-psycopg2-connection-method
If you are using the string form you need to URL escape the options argument:
postgresql://user:password@localhost:5432/database_name?options=-csearch_path%3Ddbo,public
This will connect to localhost
to database database_name
with public
schema.
This can be useful to include the schema to reduce adding the schema to each
query.
For my use case, I am going through
The Art of PostgreSQL and I want to put the
training data in a schema taop
.
Instead of updating each Python file for each query, I can just update the
connection string.