【问题标题】:MySQL connector queryMySQL 连接器查询
【发布时间】:2021-07-01 02:53:04
【问题描述】:

所以我正在尝试执行此查询,但肯定有我无法弄清楚的语法错误。 如果有人可以帮助我,将不胜感激。 :)

query = """INSERT IGNORE INTO %s(id, title, body_text, username,time_created,num_of_comments, subreddit, full_link, upvote_ratio) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"""
mycursor.execute(query, (post_table_name, tuple1),)

当前运行时错误是 result = self._cmysql.convert_to_mysql(*params) _mysql_connector.MySQLInterfaceError: Python type tuple cannot be converted

【问题讨论】:

    标签: python mysql-connector


    【解决方案1】:

    表名和字段名不能使用替换。假设您使用的是 Python 3,您可以使用 'f' 字符串:

    query = f"""INSERT IGNORE INTO {post_table_name} (id, title, body_text, username,time_created,num_of_comments, subreddit, full_link, upvote_ratio) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"""
    
    mycursor.execute(query, tuple1)
    

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 2021-06-07
      • 2016-05-19
      • 2011-11-25
      • 1970-01-01
      相关资源
      最近更新 更多