Reputation: 3288
The current data in my table is:
a b --------- -1 5 -11 2 -5 32
My request is to convert every data of column a into negative value.
But how to update the positive values into the negative selecting the entire column?
Upvotes: 4
Views: 12089
Reputation: 868
Just as @a_horse_with_no_name mentioned in his comments, the straightforward solution would be:
To negate all the existing values:
UPDATE mytable SET a = -a;
And if u want to make sure all values are negative:
UPDATE mytable SET a = -a where a > 0;
Upvotes: 0
Reputation: 7431
UPDATE mytable SET a = a * -1;
This multiplies all values in 'a' by -1. Now, if the value is already negative, it will become positive. You you want to make sure they are always negative, do this:
UPDATE mytable SET a = a * -1 WHERE a > 0;
Upvotes: 8