Skip to content

Instantly share code, notes, and snippets.

@kanghyojun
Forked from dahlia/query_debug.py
Created November 24, 2017 11:38
Show Gist options
  • Save kanghyojun/095734c1125a08d2aa070dd421ad5f17 to your computer and use it in GitHub Desktop.
Save kanghyojun/095734c1125a08d2aa070dd421ad5f17 to your computer and use it in GitHub Desktop.
Print SQLAlchemy queries (including bind params).
"""Print SQLAlchemy queries (including bind params)."""
def show_query(query):
from sqlalchemy.dialects.postgresql import dialect
qc = query.statement.compile(dialect=dialect())
return str(query) % {n: repr(b.value) for n, b in qc.binds.items()}
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