Created
October 8, 2020 14:29
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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