3

I can able to create postgres sqlalchemy connection to 'public' schema.

 url = 'postgresql://scott:tiger@localhost:5432/mydatabase'
 engine = create_engine(url)
 engine.connect()
 session = sessionmaker(bind=engine)
 Session = session()

Now try to connect non-public schema say 'myschema'.

 engine = create_engine(url, connect_args={"schema" : "myschema"})
 engine.connect()
 session = sessionmaker(bind=engine)
 Session = session()

I got error :

TypeError: connect() got an unexpected keyword argument 'schema'

How can i connect postgres by using able statements.

Thank you.

2
  • 2
    stackoverflow.com/a/49930672/4134674 Commented Mar 18, 2019 at 12:16
  • 2
    This seems really ugly/complex... there's no simpler way to just tell sqlalchemy (don't use public use "foo")? Commented Aug 31, 2020 at 15:52

1 Answer 1

1

This is valid connection string for specific schema:

engine = create_engine('postgresql://dbuser:dbpass@localhost:5432/dbname', connect_args={'options': '-csearch_path={}'.format('dbschema')})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.