MySQL 连接器查询

MySQL connector query

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

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

Table 名称和字段名称不能使用替换。假设您使用 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)