Skip to content

Instantly share code, notes, and snippets.

@robcowie
Last active August 30, 2019 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robcowie/ad8766b3fa209c1b22578059d22345ff to your computer and use it in GitHub Desktop.
Save robcowie/ad8766b3fa209c1b22578059d22345ff to your computer and use it in GitHub Desktop.
Print create SQL statement for tales and indices defined with SQLAlchemy
from sqlalchemy import create_engine, Table, MetaData
from sqlalchemy.schema import CreateIndex, CreateTable
metadata = MetaData()
engine = create_engine('')
def create_table_statement(connection, table):
stmts = []
stmts.append(CreateTable(table).compile(connection))
for index in table.indexes:
stmts.append(CreateIndex(index).compile(connection))
return stmts
for s in create_table_statement(engine, my_table):
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment