w3resource

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, and 0 if the number is zero.

Uses of SIGN() Function
  • Determining Sign: To determine the sign of a given number.

  • Conditional Logic: Useful in conditional logic where actions depend on whether a number is positive, negative, or zero.

  • Data Analysis: Employed in data analysis to categorize numbers based on their sign.

  • Mathematical Operations: To perform operations that need differentiation based on the sign of the numbers.

  • Financial Calculations: Useful in financial calculations to quickly assess profit (positive) or loss (negative) scenarios.

Syntax:

sign()

PostgreSQL Version: 9.3

Pictorial presentation of PostgreSQL SIGN() function

pictorial presentation of PostgreSQL SIGN() function

Example: PostgreSQL SIGN() function

Code:

SELECT SIGN(14.321) AS "Positive Number";

Sample Output:

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

Example : PostgreSQL SIGN() function using negative value

Code:

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

Sample Output:

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

Previous: ROUND function
Next: SIN function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/PostgreSQL/sign-function.php