[英]Passing MySQL CREATE TABLE SELECT query in Python raise syntax error
I'm trying to pass a query to sql in a loop in Python:我正在尝试在 Python 的循环中将查询传递给 sql:
for i in superstar.iloc[:, 0]:
cursor = conn.cursor()
loop_cmd = f"""
DROP TABLE IF EXISTS superstar_fwdPlusbwd_{i}; \
CREATE TABLE superstar_fwdPlusbwd_{i} \
SELECT a.*, b.CitingPatPublNr as fwd_CitingPatPublNr, c.CitedPatPublNr as bwd_CitedPatPublNr \
from orbisFirm_focals_basic_feed a \
left join patents.Patents_ForwardCitations b on a.focal_PatPublNr = b.PatPublNr \
left join patents.Patents_BackwardCitations c on a.focal_PatPublNr = c.PatPublNr \
where focal_PatPublNr = "{i}"
;
"""
cursor.execute(loop_cmd)
but this throws an syntax error:但这会引发语法错误:
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE `superstar_fwdPlusbwd_AU2002310193B2` SELECT a.*, b.CitingPatPu' at line 1")
This seems to be a syntax error inside MySql but this query worked in MySQL Workbench.这似乎是 MySql 内部的语法错误,但此查询在 MySQL 工作台中有效。 Please help, thanks!
请帮忙,谢谢!
You have not passed the parameter of columns in a Mysql table.您尚未传递 Mysql 表中的列参数。 You should have used the correct syntax to create a table Specify the column name, type,etc
您应该使用正确的语法来创建表指定列名、类型等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.