python - Passing tuple to postgres command in python
问题描述
I have a tuple having values
x = (45,96,50,60,80,70)
which is dynamic and may user add more to it, that should be passed to postgres command in python.
self._cr.execute("SELECT * FROM hr_payslip where id IN x") --> here x is the tuple variable
So the required command show be like this:
self._cr.execute("SELECT * FROM hr_payslip where id IN (45,96,50,60,80,70)")
I have tried to convert tuple to string but the column (id) required int
values.
My question is how to pass tuple value to postgres command to get the required result from it .
解决方案
我对 Odoo 了解不多,而且通过他们使用的 ORM,快速的 Google 搜索提供的很少。
可以使用类似于 python 中的格式方法的东西;类似于您在字符串中的替换方式。
所以
"SELECT * FROM hr_payslip where id IN {}".format(x)
推荐阅读
- angular - Angular - 页面加载动画
- makefile - 欺骗 gmake 构建/复制文件以保留时间戳并避免完全重建
- javascript - 运行 MutationObserver 的内容脚本与 YouTube 冲突
- html - 为什么导航元素不适用于@media 屏幕?
- python - 如何在 django 中获取和存储产品评级?
- javascript - 如何在本机反应中访问api调用响应中的特定数据
- windows - 根据文本文件列表从基本目录中删除目录的批处理文件
- django - 在序列化期间更改参数名称
- ios - FirebaseCrashlytics 自动上传符号问题
- python - Tensorflow 2.0:当输出是连续的时,指标是如何计算的?