Skip to content

Instantly share code, notes, and snippets.

@jn0
Created October 8, 2020 14:29
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 jn0/f2df50800402a7eb631f2f36e21466f1 to your computer and use it in GitHub Desktop.
Save jn0/f2df50800402a7eb631f2f36e21466f1 to your computer and use it in GitHub Desktop.
How to print *full* SQL from SQLalchemy with all the parameters substituted (still may need fixes for psql)
def SQL(query):
sql = str(query)
prm = query.compile().params.copy()
for p in prm:
t = ':' + p
sql = sql.replace(t, f'{prm[p]!r}')
return '\t'.join(sql.splitlines())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment