How to check if PostgreSQL schema exists using SQLAlchemy?

后端 未结 4 1275
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 15:07

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

4条回答
  •  春和景丽
    2021-01-12 15:39

    I've been using this with Postgres, though was surprised to learn that IF NOT EXISTS is not part of the SQL standard -

    engine.execute('CREATE SCHEMA IF NOT EXISTS foo;')
    

    Apparently it's an extension for Postgres and MySQL - https://www.w3resource.com/sql/sql-basic/create-schema.php

提交回复
热议问题