gpt4 book ai didi

mysql - Go:sql RowsAffected with ON DUPLICATE KEY UPDATE

转载 作者:数据小太阳 更新时间:2023-10-29 03:09:16 25 4
gpt4 key购买 nike

我很难找到一些合适的文档来描述 RowsAffected 值的语义,除此之外:

RowsAffected returns the number of rows affected by an update, insert, or delete. Not every database or database driver may support this.

我正在使用带有 ON DUPLICATE KEY UPDATE 的查询,更新后 RowsAffected 的值为 2。是因为删除和插入减少到执行吗?

服务器是 MySql 服务器 Ver 8.0.12 for osx10.13 on x86_64

最佳答案

mysql_affected_rows() 相当于 SQL 函数 ROW_COUNT() .

对于 INSERT .. ON DUPLICATE KEY UPDATE 文档指出:

For INSERT ... ON DUPLICATE KEY UPDATE statements, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row is updated, and 0 if an existing row is set to its current values. If you specify the CLIENT_FOUND_ROWS flag, the affected-rows value is 1 (not 0) if an existing row is set to its current values.

关于mysql - Go:sql RowsAffected with ON DUPLICATE KEY UPDATE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54867531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com