When I have a cursor, I know that I can safely execute the request as follows:
cur.execute("SELECT * FROM foo WHERE foo.bar = %s", (important_variable,))
Is there a way to just get the string safely without executing the query? For example, if important_variableis a string, for example "foo 'bar' \"baz", I would like it to be appropriately escaped:
"SELECT * FROM foo WHERE foo.bar = "foo \'bar\' \"baz"
(or whatever happens, I'm not even sure).
I am using psycopg and sqlobject.
source
share