python - psycopg - Get formatted sql instead of executing -
i have piece of python code, interacts postgresql database via psycopg.
all literature warns against doing sql formatting oneself, , recommends letting driver it. e.g.:
cur.execute('select name, age people name = %s;', ('ann',) )
the driver formats sql string. let's don't want execute anything, want formatted sql string. there functionality getting formatted sql in psycopg module?
you wold use function curs.mogrify():
sqlstring = curs.mogrify('select name, age people name = %s;', ('ann',) )
Comments
Post a Comment