There are other questions similar to mine but none of them can help me find a solution. I have a query that is
db.session.query(cls).filter_by(id=id).delete()
and I'm trying to print the exact query. I have tried to following
#1
a = db.session.query(cls).filter_by(id=id).delete()
print str(a) # gives an error
#2
a = db.session.query(cls).filter_by(id=id).delete()
print (a.statement.compile(dialect=postgresql.dialect())) # gives error like
# AttributeError: 'int' object has no attribute 'statement'
#3
query = db.session.query(cls)
print(str(query.statement.compile(
dialect=postgresql.dialect(),
compile_kwargs={"literal_binds": True})))
# prints SELECT person_data.id, person_loc.name, person.address, person.id from person_table
# doesn't show the id deletion in the query
How can I print the exact query the db session is doing during the delete?