Search code examples
javapostgresqlsqlselect-query

PostgreSQL negate a numeric value in resultset


I have a query to return a resultset of decimal(30,12) type data.

SELECT sales from invoice_index;

This query is giving me output like this:

sales
------
100
-200
300

But I need an output as follow:

sales
----
-100
200
-300

Solution

  • To negate a value, just multiply it with -1.

    SELECT sales * (-1) from invoice_index;