PostgreSQL SIGN Function

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PostgreSQL SIGN() function

SIGN() function

The PostgreSQL sign() function is used to return the sign of a given number. It returns 1 if the number is positive and -1 if negative.

Syntax :

sign()

PostgreSQL Version : 9.3

Pictorial presentation of PostgreSQL SIGN() function

 

Example : PostgreSQL SIGN() function

  1. SELECT SIGN(14.321) AS "Positive Number";  

Output :

 Positive Number
-----------------
               1
(1 row)

Example : PostgreSQL SIGN() function using negative value

  1. SELECT SIGN(-14.321) AS "Negative Number";  

Output :

 Negative Number
-----------------
              -1
(1 row)