1136, "Column count doesn't match value count at row 1"问题解决
程序员文章站
2022-03-02 13:32:36
...
我参考:python爬取拉勾网招聘信息并利用pandas做简单数据分析
写了一个python3.6 版本的脚本,部分内容如下:
sql_insert = '''INSERT INTO positions(companyId, businessZones, companyFullName, positionName,
education, city, financeStage, salary, workYear, companySize, industryField, positionAdvantage,
companyLabelList)
VALUES({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12})'''.\
format(companyId, businessZones, companyFullName, positionName, education, city, financeStage,
salary, workYear, companySize, industryField, positionAdvantage, companyLabelList)
cur.execute(sql_insert)
返回错误:
pymysql.err.InternalError: (1136, "Column count doesn't match value count at row 1")
但是将脚本改成:
sql_insert = '''INSERT INTO positions(companyId, businessZones, companyFullName, positionName,
education, city, financeStage, salary, workYear, companySize, industryField, positionAdvantage,
companyLabelList)
VALUES({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}')'''.\
format(companyId, businessZones, companyFullName, positionName, education, city, financeStage,
salary, workYear, companySize, industryField, positionAdvantage, companyLabelList)
cur.execute(sql_insert)
db.commit()
就可以插入成功。
为什么?
format()中的值本身就带有INT或者VARCHAR的特征。为什么还要给VALUES中的值加上“”?
再将脚本改成:
sql_insert = '''INSERT INTO positions(companyId, businessZones, companyFullName, positionName,
education, city, financeStage, salary, workYear, companySize, industryField, positionAdvantage,
companyLabelList)
VALUES({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12})'''.\
format(1,'2','3','4','5','6','7','8','9','10','11','12','13')
也可以运行成功,说明format()中直接引用的变量值并不是string。
但是:
难道这是一种规定的语法吗?
在sql语句中的格式化引用中如果引用对象是字符串,则必须携程‘{}’?
推荐阅读
-
Column count doesn't match value count at row 1_MySQL
-
Column count doesn't match value count at row 1_MySQL
-
ç»è®°é¡µé¢åºç°Column count doesn't match value count at row 1
-
Column count doesn't match value
-
Column count doesn't match value_PHP教程
-
Column count doesn't match value
-
注å页é¢åºç°Column count doesn't match value count at row 1
-
注å页é¢åºç°Column count doesn't match value count at row 1
-
SQL报错:Column count doesn't match value count at row 1
-
ERROR 1136 (21S01): Column count doesn't match value count at row 1