PostgreSQL sign() Function

The PostgreSQL sign() function returns the sign (-1 or 0 or +1) of a given number.

sign() Syntax

This is the syntax of the PostgreSQL sign() function:

sign(numeric_value) -> -1 | 0 | +1

Parameters

numeric_value

Required. a number.

Return value

The PostgreSQL sign(numeric_value) function returns the sign of numeric_value:

  • If the argument is a positive number, the sign() function will return 1.
  • If the argument is a negative number, the sign() function will return -1.
  • If the argument is zero, the sign() function will return 0.

The sign() function will return NULL if the argument is NULL.

PostgreSQL will give an error if you supply a parameter that is not a numeric type.

sign() Examples

This example demonstrates how to use the sign() function to get the sign of -10.

SELECT sign(-10) AS "sign(-10)";
 sign(-10)
-----------
        -1

This example demonstrates how to use the sign() function to get the sign of 10.

SELECT sign(10) AS "sign(10)";
 sign(10)
----------
        1

This example demonstrates how to use the sign() function to get the sign of 0.

SELECT sign(0) AS "sign(0)";
 sign(0)
---------
       0