V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
U87
V2EX  ›  问与答

pymysql 入库 %s 占位符问题

  •  
  •   U87 · 2018-08-21 13:42:24 +08:00 · 1467 次点击
    这是一个创建于 2047 天前的主题,其中的信息可能已经有所发展或是发生改变。

    sql = "INSERT INTO %s (%s) VALUES (%s)" val=(table, fields[:-1], values[:-1]) cursor.execute(sql, val) 我这边这么格式化参数对的.但是入库时报错 1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 请问是什么情况

    2 条回复    2018-08-21 13:59:37 +08:00
    sujin190
        1
    sujin190  
       2018-08-21 13:57:27 +08:00
    你把一个数组直接转成字符串扔给 mysql 运行肯定挂啊
    blankme
        2
    blankme  
       2018-08-21 13:59:37 +08:00
    table name 不能直接作为变量传入
    psycopg2 的相关说明: http://initd.org/psycopg/docs/sql.html
    pymysql 应该也有相应的处理方式
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4603 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:51 · PVG 17:51 · LAX 02:51 · JFK 05:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.