Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python变量中存储SQL查询的输出_Python_Sql - Fatal编程技术网

在Python变量中存储SQL查询的输出

在Python变量中存储SQL查询的输出,python,sql,Python,Sql,关于,我尝试修改我的SQL查询,如下所示: query2 ="""insert into table xyz(select * from abc where date_time > %s and date_time <= ( %s + interval '1 hour'))""" cur.execute(query2,(rows,rows)) 是否有解决此错误的方法?您的查询有可疑之处,它看起来不正确: insert into table xyz (select * from ab

关于,我尝试修改我的SQL查询,如下所示:

query2 ="""insert into table xyz(select * from abc where date_time > %s and date_time <= ( %s + interval '1 hour'))"""
cur.execute(query2,(rows,rows))

是否有解决此错误的方法?

您的查询有可疑之处,它看起来不正确:

insert into table xyz
(select * from abc where date_time = %s and %s + interval '1 hour')
我建议:

insert into xyz (<columns of xyz>)
select <columns of abc> 
from abc 
where date_time > ?  
查询字符串中参数标记(?)的数量应等于元组中元素的数量

如果在查询中使用%s(不建议使用),则可以通过以下方式为这些变量赋值:

"""insert into xyz (<columns of xyz>)
   select <columns of abc> 
   from abc 
   where date_time > %s""" % (value)
“插入到xyz()
挑选
来自美国广播公司
其中日期时间>%s”“”%(值)

什么是完整的回溯?请不要再次发布相同的问题。可能重复的问题不相同。这是对我已经问过的问题的补充。您在自己的问题上发布的答案有1行变量,而不是2行变量-这就是您在这里提出的问题。您能更具体一点吗?
insert into xyz (<columns of xyz>)
select <columns of abc> 
from abc 
where date_time > ? and date_time <= ? + interval '1 hour'
cur.execute(query2,(ts, ts))
"""insert into xyz (<columns of xyz>)
   select <columns of abc> 
   from abc 
   where date_time > %s""" % (value)