I am using SQLAlchemy to generate tables in a specific schema in a PostgreSQL database. If the schema does not exist, I want to create it. I know the PostgreSQL query to che
@javax's answer is almost correct; the following is a little clarification:
q = exists(select([("schema_name")]).select_from("information_schema.schemata") .where("schema_name = 'foo'")) if not session.query(q).scalar(): session.execute('CREATE SCHEMA foo;')