SQLite 3 reference · Math Functions

SQLite SIGN() Function

Return -1, 0 or 1 depending on whether a number is negative, zero or positive. Non-numeric text gives NULL.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

sign(X)

Parameters

ParameterDescription
X A number (text that looks like a number is converted).

Return value

-1, 0, 1, or NULL.

Examples

The sign of numbersTry it yourself
SELECT sign(-3) AS neg, sign(0) AS zero, sign(2.5) AS pos;

Output

neg | zero | pos
-1 | 0 | 1
Branch on the signTry it yourself
SELECT name, stock,
       CASE sign(stock) WHEN 0 THEN 'sold out' ELSE 'in stock' END AS status
FROM products
WHERE product_id IN (2, 3);

Output

name | stock | status
Clean Code | 15 | in stock
The Pragmatic Programmer | 0 | sold out

Was this page helpful?