Functions that return one of their arguments by evaluating in an if-else manner.
Synopsis:
Input:
…
Nth expression
COALESCE can take an arbitrary number of arguments.
Output: one of the expressions or null
Description. Returns the first of its arguments that is not null.
If all arguments are null, then it returns null.
SELECT COALESCE(null, 'elastic', 'search') AS "coalesce";
coalesce
---------------
elasticSELECT COALESCE(null, null, null, null) AS "coalesce";
coalesce
---------------
nullSynopsis:
Input:
…
Nth expression
GREATEST can take an arbitrary number of arguments and all of them must be of the same data type.
Output: one of the expressions or null
Description. Returns the argument that has the largest value which is not null.
If all arguments are null, then it returns null.
SELECT GREATEST(null, 1, 2) AS "greatest";
greatest
---------------
2SELECT GREATEST(null, null, null, null) AS "greatest";
greatest
---------------
nullSynopsis:
Input:
Output: 2nd expression if 1st expression is null, otherwise 1st expression.
Description. Variant of COALESCE with only two arguments.
Returns the first of its arguments that is not null.
If all arguments are null, then it returns null.
SELECT IFNULL('elastic', null) AS "ifnull";
ifnull
---------------
elasticSELECT IFNULL(null, 'search') AS "ifnull";
ifnull
---------------
searchSynopsis:
Input:
Output: 2nd expression if 1st expression is null, otherwise 1st expression.
Description. Variant of COALESCE with only two arguments.
Returns the first of its arguments that is not null.
If all arguments are null, then it returns null.
SELECT ISNULL('elastic', null) AS "isnull";
isnull
---------------
elasticSELECT ISNULL(null, 'search') AS "isnull";
isnull
---------------
searchSynopsis:
Input:
…
Nth expression
LEAST can take an arbitrary number of arguments and all of them must be of the same data type.
Output: one of the expressions or null
Description. Returns the argument that has the smallest value which is not null.
If all arguments are null, then it returns null.
SELECT LEAST(null, 2, 1) AS "least";
least
---------------
1SELECT LEAST(null, null, null, null) AS "least";
least
---------------
nullSynopsis:
Input:
Output: null if the 2 expressions are equal, otherwise the 1st expression.
Description. Returns null when the two input expressions are equal and
if not, it returns the 1st expression.
SELECT NULLIF('elastic', 'search') AS "nullif";
nullif
---------------
elasticSELECT NULLIF('elastic', 'elastic') AS "nullif";
nullif:s
---------------
nullSynopsis:
Input:
Output: 2nd expression if 1st expression is null, otherwise 1st expression.
Description. Variant of COALESCE with only two arguments.
Returns the first of its arguments that is not null.
If all arguments are null, then it returns null.
SELECT NVL('elastic', null) AS "nvl";
nvl
---------------
elasticSELECT NVL(null, 'search') AS "nvl";
nvl
---------------
search