Given a sql query such as
query = """
select some_col from tbl where some_col > :value
"""
I'm executing this with sqlalchemy using
connection.execute(sa.text(query), {'value' : 5})
Though this does what's expected, I would like to be able to get the raw sql, with replaced parameters. Meaning I would like a way to be able to get
select some_column from tbl where some_column > 5
I've tried to echo the sql using:
engine = sa.create_engine(
'<CONNECTION STRING>',
echo=True,
)
But this didn't replace the parameters.
If there's not a way to do this in sqlalchemy, but is a way using something like psycopg2 (as long as the syntax :value doesn't change) then that would be of interest.
qis different to the raw string that I have in my example.select col1 from Tandselect col2 from Tto work with a parameter'col1'and'col2'. You can't pass table or column names in a way as you pass a value inwhere col = :id- you need a dynamic SQL @baxx