简体   繁体   English

将元组传递给python中的postgres命令

[英]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. 这是动态的,可能会向用户添加更多,应该在python中传递给postgres命令。

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. 我试图将元组转换为字符串,但列(id)需要int值。

My question is how to pass tuple value to postgres command to get the required result from it . 我的问题是如何将元组值传递给postgres命令以从中获取所需的结果。

I don't know much about Odoo and a quick Google Search provides very little by means of the ORM they use. 我对Odoo知之甚少,而快速的Google搜索所提供的ORM却很少。

Something along the lines of the format method in python could be used; 可以使用python中format方法的一些东西; similar to how you substitute in strings. 类似于替换字符串的方式。

So 所以

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM