SIGN

The SIGN function takes a single argument, which can be any numeric data type such as INTEGER, FLOAT, or DECIMAL, and returns an INT value of -1, 0, or 1, depending on the sign of the input argument.

Syntax

SELECT SIGN(expr);

Arguments

Parameter

Description

numeric_expression

Numeric data types

Return

Returns an output of the same data type as the input data type.

Depending on the sign of the input argument, the return is:

  • -1, if the input expression is negative

  • 0, if the input expression is zero

  • 1, if the input expression is positive

Example

SELECT SIGN(-10), SIGN(0), SIGN(5) ;

Output:

sign | sign0 | sign1
-----+------+-------
  -1 |   0  |   1