我正在使用 psycopg3,想看看带有参数的实际 sql 是什么,以便我可以使用 dbweaver 执行它...
with psycopg.connect(self.connect_str, autocommit=True) as conn:
if self.log.level == logging.DEBUG:
cur = conn.cursor()
sql_mogr = cur.mogrify(sql, params)
self.log.debug(sql_mogr)
else:
self.log.info(f'sql: {sql}, params:{params}')
df = pd.read_sql(sql, con = conn, params = params)
mogrify 线的结果是:
AttributeError: 'Cursor' object has no attribute 'mogrify'
psycopg3不支持这种方法吗?如果没有,替代解决方案是什么?
psycopg 版本:
psycopg==3.1.18
psycopg-binary==3.1.18
psycopg-pool==3.2.1
mogrify
方法仅适用于ClientCursor类。
>>> conn = psycopg.connect(dbname='test', cursor_factory=psycopg.ClientCursor)
>>> cur = conn.cursor()
>>> q = """select * from users"""
>>> cur.mogrify(q)
'select * from users'