如何使用peewee设置或选择postgres当前的\u设置?

2024-04-19 16:23:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个postgres数据库,我想用python中的peewee查询它。如果我直接连接到数据库(psql或pgadmin),我可以执行以下操作

set my.setting='test'

或者

select current_setting('my.setting')

我怎么能和皮维一起?我的模型只包含数据库中的表。你知道吗

谢谢你的帮助!你知道吗


Tags: 模型test数据库mypostgrescurrentselectsetting
1条回答
网友
1楼 · 发布于 2024-04-19 16:23:07

可以使用Database方法^{}执行原始SQL示例:

db = PostgresqlDatabase("test")
db.execute_sql("set my.setting to 'test'")
cur = db.execute_sql("show my.setting")
print(cur.fetchone()[0])

相关问题 更多 >