Veerasundaravel's Ruby on Rails Weblog

November 2, 2007

Postgresql update count returning issue

Filed under: DB — Tags: , , , , , , — Veerasundaravel @ 6:03 am

In postgres, while you updating the a record with same value it will still returns effected rows count as 1 only, but mysql is not returning like this.

I surfed through lot of blogs and forums but no luck, Finally I found the solution mysql like below.

update users set is_active = true where id = 1
1 row(s) affected.

again the same query

update users set is_active = true where id = 1
1 row(s) affected. # Here it should return 0 row(s) affected right, cos it already modified the value of is_active in first query. In second query it doesn’t updated the value.

So I decided to update the query as follows:

update users set is_active = true where id = 1 and is_active != true
1 row(s) affected.

update users set is_active = true where id = 1 and is_active != true
0 row(s) affected.

%d bloggers like this: