Skip to content

Instantly share code, notes, and snippets.

@dahlia
Last active May 4, 2018 18:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dahlia/445d8bc2e8f0c7fb045685cda5a498ac to your computer and use it in GitHub Desktop.
Save dahlia/445d8bc2e8f0c7fb045685cda5a498ac to your computer and use it in GitHub Desktop.
Print SQLAlchemy queries (including bind params).
"""Print SQLAlchemy queries (including bind params).
See also: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html#faq-sql-expression-string
"""
def show_query(query):
qc = query.statement.compile(
dialect=query.session.bind.dialect,
compile_kwargs={'literal_binds': True}
)
return str(query)
def print_query(query):
print(show_query(query))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment