Convert positive data to non-loadable data (entire column) in Postgres Server

Current data in my table:

ab --------- -1 5 -11 2 -5 32 

My query is to convert all the data of column a to a negative value.

But how to update positive values ​​in a negative selection of an entire column?

+5
source share
2 answers

Try the following:

  Update table set a= 0-a where a >0 
+7
source

UPDATE mytable SET a = a * -1;

This multiplies all the values ​​in 'a' by -1. Now, if the value is already negative, it will become positive. You want them to always be negative, do the following:

UPDATE mytable SET a = a * -1 WHERE a > 0;

+6
source

Source: https://habr.com/ru/post/1242942/


All Articles