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
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
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://w3resource.com/PostgreSQL/sign-function.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics