首页 > 解决方案 > 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 .

标签: pythonpostgresql

解决方案


我对 Odoo 了解不多,而且通过他们使用的 ORM,快速的 Google 搜索提供的很少。

可以使用类似于 python 中的格式方法的东西;类似于您在字符串中的替换方式。

所以

"SELECT * FROM hr_payslip where id IN {}".format(x)

推荐阅读