VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Numeric Functions
SIGN

SIGN

Description

Returns the sign of x. Negative, zero or positive numbers correspond to -1, 0 or 1 respectively.

Syntax

SIGN(x)

Parameters

ParameterDescription
<x>independent variable

Return value

Returns an integer:

  • If x > 0, it returns 1, representing a positive number.

  • If x = 0, it returns 0, representing zero.

  • If x < 0, it returns -1, representing a negative number.

  • If x is NULL, it returns NULL.

Example

select sign(3);
+-------------------------+
| sign(cast(3 as DOUBLE)) |
+-------------------------+
|                       1 |
+-------------------------+
select sign(0);
+-------------------------+
| sign(cast(0 as DOUBLE)) |
+-------------------------+
|                       0 |
+-------------------------+
select sign(-10.0);
+-----------------------------+
| sign(cast(-10.0 as DOUBLE)) |
+-----------------------------+
|                          -1 |
+-----------------------------+
select sign(null);
+------------+
| sign(NULL) |
+------------+
|       NULL |
+------------+