dqgo99177 2014-08-25 13:25
浏览 765
已采纳

ON DUPLICATE KEY UPDATE上的SQL语法错误

I have this table that I want to update / insert with one statement currently using ON DUPLICATE KEY UPDATE:

index (INT) user(INT) entryId(INT) tags(text)
1              1          111      ||bla||
2              1          111      ||bla||
3              1          111      ||bla||

INSERT INTO filters (index,user,entryId,tags) VALUES (1,1,'100003817186741',"||test1||||test2||"), (3,1,'100003021196089',"||test1||||test2||") ON DUPLICATE KEY UPDATE user=VALUES(user),entryId=VALUES(entryId),tags=VALUES(tags)

Why does this fail with an SQL syntax error?

  • 写回答

3条回答 默认 最新

  • dongzhang5006 2014-08-25 13:29
    关注

    It fails because index is a MySQL reserved word.

    http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

    either wrap it in backticks or choose another word for it

    INSERT INTO filters (index,user,entryId,tags)
                         ^    ^
    

    do

    INSERT INTO filters (`index`,user,entryId,tags)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序