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.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: