pgx icon indicating copy to clipboard operation
pgx copied to clipboard

Why the row affected still have no zero even field in column are not updated actually same value

Open umardev500 opened this issue 1 year ago • 1 comments

func (repo *wasteTypeRepo) UpdateByID(ctx context.Context, payload model.WasteTypeUpdateWithVersionRequest) error { fmt.Println(payload.SOURCEID) queries := repo.pgxConfig.TrOrDB(ctx) sql := --sql UPDATE waste_types SET "name" = 'bar'

result, err := queries.Exec(ctx, sql)
fmt.Println(result.RowsAffected())

return err

}

umardev500 avatar May 23 '24 06:05 umardev500

It's hard to understand what do you mean, but if I understand you correctly - you ask why do you get affected rows count greater than 0 even if you try to update column using the same value.

Actually its how does PostgreSQL MVCC works, nothing to do with pgx. When you update column in a row it doesn't matter was value actually changed or not - PostgreSQL will overwrite entire row (with some exception to TOASTed columns).

So there's no any bug with pgx.

codercms avatar Jun 13 '24 14:06 codercms