简体   繁体   English

Peewee:如何选择ID匹配列表的多行?

[英]Peewee: how to select multiple rows where id matches the list?

list_of_ids = "23,55,11,24"
job = Job.select().join(User).where(Job.id IN (list_of_ids))

I want to get all jobs belonging to a specific User where the job id's matching the list of ids provided. 我想获取属于特定用户的所有作业,其中作业ID与提供list of ids匹配。 However, I keep getting syntax error and I can't find any documentation on this on the Peewee website. 但是,我一直收到语法错误,并且在Peewee网站上找不到任何文档。

I want to be able to do update and delete operations as well on the list of ids provided. 我希望能够对提供的ID列表进行更新和删除操作。

It would be nice if Peewee could just let me insert a SQL string. 如果Peewee可以让我插入一个SQL字符串,那就太好了。 I would just do 我会做

SELECT job.name FROM user INNER JOIN job ON user.id = job.id 
WHERE job.id IN (23,55,11,24)

You want something like: 您想要类似的东西:

Job.select().join(User).where(Job.id << list_of_ids.split(','))

x << y will do x IN y, where y is a list or query as described here: https://peewee.readthedocs.io/en/latest/peewee/query_operators.html x << y将执行x IN y,其中y是列表或查询 ,如此处所述: https : //peewee.readthedocs.io/en/latest/peewee/query_operators.html

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

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