Skip to content

Instantly share code, notes, and snippets.

@ksomemo
Forked from kwatch/gist:4672421
Created December 25, 2019 14:51
Show Gist options
  • Select an option

  • Save ksomemo/890d2cfef1491185dec2bf566751ab99 to your computer and use it in GitHub Desktop.

Select an option

Save ksomemo/890d2cfef1491185dec2bf566751ab99 to your computer and use it in GitHub Desktop.

Revisions

  1. @kwatch kwatch revised this gist Jan 30, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    def query2sql(query):
    """convert query object into non-prepared sql string in SQLAlchemy and psycopg2"""
    compiler = query.statement.compile()
    params = compiler.params
    prepared_sql = compiler.string # or str(compiler)
  2. @kwatch kwatch created this gist Jan 30, 2013.
    7 changes: 7 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    def query2sql(query):
    compiler = query.statement.compile()
    params = compiler.params
    prepared_sql = compiler.string # or str(compiler)
    psycopg2_cursor = query.session.connection().connection.cursor()
    sql = psycopg2_cursor.mogrify(prepared_sql, params)
    return sql