I'm trying to connect to a postgres db using SQL Alchemy and the pg8000 driver. I'd like to specify a search path for this connection. With the Psycopg driver, I could do this by doing something like
engine = create_engine(
'postgresql+psycopg2://dbuser@dbhost:5432/dbname',
connect_args={'options': '-csearch_path={}'.format(dbschema)})
However, this does not work for the pg8000 driver. Is there a good way to do this?
You can use
pg8000pretty much in the same way aspsycopg2, just need to swap scheme frompostgresql+psycopg2topostgresql+pg8000.The full connection string definition is in the SQLAlchemy
pg8000docs:But while
psycopg2.connectwill pass kwargs to the server (likeoptionsand its content),pg8000.connectwill not, so there is no settingsearch_pathwithpg8000.