psycopg - Get formatted sql instead of executing

前端 未结 2 414
抹茶落季
抹茶落季 2020-12-18 21:02

I have a piece of Python code, that interacts with a PostgreSQL database via psycopg.

All literature warns against doing sql formatting by oneself, and recommends l

2条回答
  •  不知归路
    2020-12-18 21:31

    you wold use function curs.mogrify():

    SQLstring = curs.mogrify('select name, age from people where name = %s;', ('ann',) )
    

提交回复
热议问题