SQLite: bind list of values to “WHERE col IN ( :PRM )”

后端 未结 9 674
轮回少年
轮回少年 2020-12-16 09:53

all I want to do is send a query like

SELECT * FROM table WHERE col IN (110, 130, 90);

So I prepared the following statement



        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 10:42

    For example, if you want the sql query:

    select * from table where col in (110, 130, 90)
    

    What about:

    my_list = [110, 130, 90]
    my_list_str = repr(my_list).replace('[','(').replace(']',')') 
    cur.execute("select * from table where col in %s" % my_list_str )
    

提交回复
热议问题