gpt4 book ai didi

python - mysql 查询不起作用

转载 作者:行者123 更新时间:2023-11-29 12:55:24 24 4
gpt4 key购买 nike

我正在尝试使用以下 Python 脚本将数据加载到 MySQL 表中:

conn = connect_db()
cursor = conn.cursor()
cursor.execute(
"LOAD DATA LOCAL INFILE " + jobsummaryfile + " INTO TABLE daily_job_summary " +
"FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4) " +
"set jobname=@col1, queue=@col2, maphours=@col3, reducehours=@col4, date=" + date +
", pipeline=" + pipeline_name + ", grid=" + grid
)

我收到以下错误:

_mysql_exceptions.OperationalError: (1054, "Unknown column 'galaxy' in 'field list'")

我知道这是传递查询时的引号问题,但我很难弄清楚它。有人可以建议我在哪里犯了错误吗?

这是我要执行的查询:

LOAD DATA LOCAL INFILE 'file.tsv' 
INTO TABLE daily_job_summary
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
(@col1, @col2, @col3, @col4)
set jobname=@col1, queue=@col2, maphours=@col3, reducehours=@col4,
date=2014-01-05, pipeline='abcd', grid='AB'

这是我的表结构:

| id          | int(11)      | NO   | PRI | NULL    | auto_increment |  
| date | date | YES | | NULL | |
| pipeline | varchar(12) | YES | | NULL | |
| grid | varchar(2) | YES | | NULL | |
| jobname | varchar(255) | YES | | NULL | |
| maphours | int(11) | YES | | NULL | |
| reducehours | int(11) | YES | | NULL | |
| queue | varchar(60) | YES | | NULL | |

最佳答案

看来您需要为 pipeline_namegrid 添加引号

 cursor.execute(" ... pipeline='"+pipeline_name+"', grid='"+grid+"'")

关于python - mysql 查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24131196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com