On Sun, Jul 31, 2022, at 10:15 PM, [email protected] wrote: > Hello, > > I’m curious to get recommendations about the following use-case (based on > this SO Answer > <https://stackoverflow.com/questions/50927740/sqlalchemy-create-schema-if-not-exists#55345404>): > > *>>> import sqlalchemy* > *>>> configuration = {'sqlalchemy.url': > 'postgresql+psycopg2://postgres:postgres@localhost/test_db'}* > *>>> engine = sqlalchemy.engine_from_config(configuration, future=True)* > *>>> engine.dialect.has_schema(engine, schema) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File > "/.../lib/python3.10/site-packages/sqlalchemy/dialects/postgresql/base.py", > line 3360, in has_schema > cursor = connection.execute( > File "/.../lib/python3.10/site-packages/sqlalchemy/future/engine.py", line > 320, in _not_implemented > raise NotImplementedError( > NotImplementedError: This method is not implemented for SQLAlchemy 2.0.* > > This works if I turn off the future > <https://docs.sqlalchemy.org/en/14/core/engines.html#sqlalchemy.create_engine.params.future> > flag: > > *>>> engine = sqlalchemy.engine_from_config(configuration) > >>> engine.dialect.has_schema(engine, schema) > False* > > Is there a fix coming? Is there an alternative suggestion? Interestingly, I > wasn’t able to find *has_schema()* in SQLA v1.4 > <https://docs.sqlalchemy.org/en/14/core/internals.html#sqlalchemy.engine.Dialect> > (although v0.7 says it was added > <https://docs.sqlalchemy.org/en/14/search.html?q=has_schema>) but only for > SQLA v2 > <https://docs.sqlalchemy.org/en/20/core/internals.html#sqlalchemy.engine.Dialect.has_schema>.
it's because that is not user-facing API, that's for dialect authors and 1.4 does not have official public API for this function. in 2.0 you would use inspector.has_schema(): https://docs.sqlalchemy.org/en/20/core/reflection.html?highlight=inspector+has_schema#sqlalchemy.engine.reflection.Inspector.has_schema > > For now I can use an “old” engine to check for schema, and the switch to a > new one, but what’s the current recommendation? > > Much thanks! > Jens > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/2101bd77-7dbd-4ba1-8bd1-203eadee754cn%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/2101bd77-7dbd-4ba1-8bd1-203eadee754cn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/f3d8d54f-5bf6-4671-8774-ad20098f5ee6%40www.fastmail.com.
