The advised way to run a parameterized query with psycopg2, if I understand correctly, is to use the second argument to the execute method:
SQL = "INSERT INTO authors (name) VALUES (%s);"
data = ("O'Reilly", )
cur.execute(SQL, data)
This will sanitize the data, do quoting, etc. That's great. Less great is it appears to be opaque; it seems to be a black box that modifies my code. I'd like to see what the actual query sent to the database is. Is there some way to see that?