python - 插入条件

标签 python mysql python-2.7 python-3.x pymysql

我正在使用 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/

相关文章:

php - 流式传输多条推文 - 来自多个用户? - 推特 API

python - Selenium 独立服务器日志级别

mysql - 子查询的 group by 计数与 group by 列上的不同计数之间的差异

Mysql - 使用连接删除与两个删除语句

Python-我想使用 pandas 将第二行的列移动到第一行的列

python - html对css无效

python - 如何使用 celery-beat 启动任务?

mysql - 在 MySQL 中查找同一个表中的重复项

python - 与 4 之和相切的组合的组合

file - PyQt 打开文件对话框 - 显示路径名称