我正在使用 python 并使用 pymysql 库,我想编写一个查询,在列具有某些特殊值的行中插入数组。 例如,将“hi”插入到 user_id 为 22 的列中 对于该查询我写了这段代码 从 pymysql 导入 * 聊天 ID = 22 user_first_name =“嗨”
db = connect(host="localhost", port=3306, user="root", passwd="",
db='support',charset='utf8')
cursor = db.cursor()
cursor.execute("""INSERT INTO users user_firstname VALUE %s WHERE user_id is
%s""",(user_first_name, chat_id))
db.commit()
我应该如何以正确的形式编写这个查询?
最佳答案
如果我理解正确,而不是INSERT INTO
,那么您似乎需要UPDATE
:
cursor.execute("""UPDATE users SET user_firstname='%s' WHERE user_id=%s""",(user_first_name, chat_id))
关于python - 插入条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46408318/