Conditional Functions for Numbers
- reference
Conditional functions evaluate expressions to determine if the values and formulas meet the specified condition.
IFINF(expr1, expr2, …)
This function has a synonym IF_INF().
Description
Evaluates a list of expressions and returns the first finite number.
The function ignores MISSING and infinite values.
If it encounters NULL or any non-numeric value before finding a finite number, the function returns NULL.
Arguments
- expr1, expr2, …
-
[Required] A list of valid expressions to evaluate. You must specify at least 2 expressions.
Return Value
The function returns 1 of the following:
-
The first finite number.
-
NULLif it encountersNULLor a non-number before finding a finite number.
Example
SELECT IFINF(5, 10, 20),
IFINF(INF(), -INF(), 5, 10),
IFINF(POWER(10, 400), 5, 10),
IFINF(2.001e340, 5),
IFINF(NULL, 5, 10),
IFINF(MISSING, 5, NULL),
IFINF(MISSING, NULL, 5, 10);
[
{
"$1": 5,
"$2": 5,
"$3": 5,
"$4": 5,
"$5": null,
"$6": 5,
"$7": null
}
]
In this example:
-
The functions
INF()and-INF()return positive and negative infinity, respectively. -
The function
POWER(10, 400)and the expression2.001e340return positive infinity because they exceed the maximum representable finite number.
IFNAN(expr1, expr2, …)
This function has a synonym IF_NAN().
Description
Evaluates a list of expressions and returns the first valid number that’s not NaN (Not a Number).
The function ignores MISSING and NaN values.
If it encounters NULL or any other non-number before finding a valid number, the function returns NULL.
Arguments
- expr1, expr2, …
-
[Required] A list of valid expressions to evaluate. You must specify at least 2 expressions.
Return Value
The function returns 1 of the following:
-
The first valid number.
-
NULLif it encountersNULLor a non-number before finding a number.
Example
SELECT IFNAN(5, 10, 20, NAN()),
IFNAN(SQRT(-1), 5, 10),
IFNAN("abc", 5, NULL, 10),
IFNAN(NULL, 5, 10),
IFNAN(MISSING, 5, NULL),
IFNAN(MISSING, NULL, 5, 10),
IFNAN(NAN(), 5, 10);
[
{
"$1": 5,
"$2": 5,
"$3": null,
"$4": null,
"$5": 5,
"$6": null,
"$7": 5
}
]
In this example:
-
The function
NAN()returns a NaN value. -
The function
SQRT(-1)also returns NaN because the square root of a negative number is not a real number.
IFNANORINF(expr1, expr2, …)
This function has a synonym IF_NAN_OR_INF().
Description
Evaluates a list of expressions and returns the first number that’s neither NaN (Not a Number) nor infinite.
The function skips MISSING, NaN, and infinite values.
If it encounters NULL or any other non-number before finding a valid number, the function returns NULL.
Arguments
- expr1, expr2, …
-
[Required] A list of valid expressions to evaluate. You must specify at least 2 expressions.
Return Value
The function returns 1 of the following:
-
The first number that’s neither NaN nor infinite.
-
NULLif it encountersNULLor a non-number before finding such a number.
Example
SELECT IFNANORINF(5, 10, NAN(), INF()),
IFNANORINF(SQRT(-1), -INF(), 5, 10),
IFNANORINF(2.001e340, 5, 10),
IFNANORINF("abc", 5, NULL, 10),
IFNANORINF(NULL, 5, 10),
IFNANORINF(MISSING, 5, NULL);
[
{
"$1": 5,
"$2": 5,
"$3": 5,
"$4": null,
"$5": null,
"$6": 5
}
]
In this example:
-
The function
NAN()returns a NaN value. -
The functions
INF()and-INF()return positive and negative infinity, respectively. -
The function
SQRT(-1)returns NaN because the square root of a negative number is not a real number. -
The expression
2.001e340returns positive infinity because it exceeds the maximum representable finite number.
NANIF(expr1, expr2)
This function has a synonym NAN_IF().
Description
Compares 2 expressions and returns NaN (Not a Number) if they’re equal; otherwise, it returns the value of the first expression.
Arguments
- expr1
-
[Required] A valid expression.
- expr2
-
[Required] A valid expression to compare with
expr1.
NEGINFIF(expr1, expr2)
This function has a synonym NEGINF_IF().
Description
Compares 2 expressions and returns negative infinity if they’re equal; otherwise, it returns the value of the first expression.
Arguments
- expr1
-
[Required] A valid expression.
- expr2
-
[Required] A valid expression to compare with
expr1.
POSINFIF(expr1, expr2)
This function has a synonym POSINF_IF().
Description
Compares 2 expressions and returns positive infinity if they’re equal; otherwise, it returns the value of the first expression.
Arguments
- expr1
-
[Required] A valid expression.
- expr2
-
[Required] A valid expression to compare with
expr1.