python中sqlite的嵌套insert和select子句中的倒逗号

python中sqlite的嵌套insert和select子句中的倒逗号,python,sqlite,Python,Sqlite,我在以下sqlite语句中放置正确的QOUTE时遇到了问题,该语句将customer idc_id(customers表的主键)放置到place表的外键c_id中 我可以通过取消嵌套代码并执行“selectc_id fromscustomers”部分(其中fname=?)来提取c_id?分别地然而,我希望我的代码更加简洁 t = (fname,) place = (postal_code , place_name) cur.execute(""insert into place(postal_c

我在以下sqlite语句中放置正确的QOUTE时遇到了问题,该语句将customer idc_id(customers表的主键)放置到place表的外键c_id中

我可以通过取消嵌套代码并执行“selectc_id fromscustomers”部分(其中fname=?)来提取c_id?分别地然而,我希望我的代码更加简洁

t = (fname,)
place = (postal_code , place_name)
cur.execute(""insert into place(postal_code ,place_name,c_id) values(?,?,("select c_id from customers where fname =?"),t)""",place)
报价都不合适,请帮忙解决


顺便说一句:这个问题与这个问题类似,我从中复制了嵌套的概念

我完全在猜,但你试过了吗

cur.execute("insert into place(postal_code ,place_name,c_id) values(?,?,(select c_id from customers where fname = ?))", (postal_code , place_name, fname))
编辑 看到这个问题了吗


这个问题的解决方案不在于正确引用,而在于采用sqlite语句的形式

一种解决方案是使用三个值设计变量位置,其中一个值带有客户idc\U id的外键

place = (postal_code , place , f_name) 

cur.execute("insert into place(postal_code ,place,f_name) values(?,?,(select c_id from customers where fname =?))",place)

这是python中倒逗号的问题。我必须正确地放置它们,以便编译器理解值中的select子句是sql语句,而不是其他语句。它给出了错误:cur.executeinsert into place邮政编码,place,c_id值?,?,从客户处选择c_id,其中fname=?,place,fname TypeError:函数最多接受2个参数3
place = (postal_code , place , f_name) 

cur.execute("insert into place(postal_code ,place,f_name) values(?,?,(select c_id from customers where fname =?))",place)