GoogleSQL for Bigtable supports the following debugging functions.
Function list
| Name | Summary |
|---|---|
IFERROR
|
Evaluates a try expression, and if an evaluation error is produced, returns the result of a catch expression. |
ISERROR
|
Evaluates a try expression, and if an evaluation error is produced, returns
TRUE.
|
NULLIFERROR
|
Evaluates a try expression, and if an evaluation error is produced, returns
NULL.
|
IFERROR
IFERROR(try_expression, catch_expression)
Description
Evaluates try_expression.
When try_expression is evaluated:
- If the evaluation of
try_expressiondoesn't produce an error, thenIFERRORreturns the result oftry_expressionwithout evaluatingcatch_expression. - If the evaluation of
try_expressionproduces a system error, thenIFERRORproduces that system error. - If the evaluation of
try_expressionproduces an evaluation error, thenIFERRORsuppresses that evaluation error and evaluatescatch_expression.
If catch_expression is evaluated:
- If the evaluation of
catch_expressiondoesn't produce an error, thenIFERRORreturns the result ofcatch_expression. - If the evaluation of
catch_expressionproduces any error, thenIFERRORproduces that error.
Arguments
try_expression: An expression that returns a scalar value.catch_expression: An expression that returns a scalar value.
The results of try_expression and catch_expression must share a
supertype.
Return Data Type
The supertype for try_expression and
catch_expression.
Example
In the following example, the query successfully evaluates try_expression.
SELECT IFERROR('a', 'b') AS result
/*--------*
| result |
+--------+
| a |
*--------*/
In the following example, IFERROR catches an evaluation error in the
try_expression and successfully evaluates catch_expression.
SELECT IFERROR(ERROR('a'), 'b') AS result
/*--------*
| result |
+--------+
| b |
*--------*/
In the following query, the error is handled by the innermost IFERROR
operation, IFERROR(ERROR('a'), 'b').
SELECT IFERROR(IFERROR(ERROR('a'), 'b'), 'c') AS result
/*--------*
| result |
+--------+
| b |
*--------*/
In the following query, the error is handled by the outermost IFERROR
operation, IFERROR(..., 'c').
SELECT IFERROR(IFERROR(ERROR('a'), ERROR('b')), 'c') AS result
/*--------*
| result |
+--------+
| c |
*--------*/
In the following example, IFERROR catches an evaluation error in ERROR('a')
and then evaluates ERROR('b'). Because there is also an evaluation error in
ERROR('b'), IFERROR produces an evaluation error for ERROR('b').
SELECT IFERROR(ERROR('a'), ERROR('b')) AS result
--ERROR: OUT_OF_RANGE 'b'
ISERROR
ISERROR(try_expression)
Description
Evaluates try_expression.
- If the evaluation of
try_expressiondoesn't produce an error, thenISERRORreturnsFALSE. - If the evaluation of
try_expressionproduces a system error, thenISERRORproduces that system error. - If the evaluation of
try_expressionproduces an evaluation error, thenISERRORreturnsTRUE.
Arguments
try_expression: An expression that returns a scalar value.
Return Data Type
BOOL
Example
In the following examples, ISERROR successfully evaluates try_expression.
SELECT ISERROR('a') AS is_error
/*----------*
| is_error |
+----------+
| false |
*----------*/
SELECT ISERROR(2/1) AS is_error
/*----------*
| is_error |
+----------+
| false |
*----------*/
In the following examples, ISERROR catches an evaluation error in
try_expression.
SELECT ISERROR(ERROR('a')) AS is_error
/*----------*
| is_error |
+----------+
| true |
*----------*/
SELECT ISERROR(2/0) AS is_error
/*----------*
| is_error |
+----------+
| true |
*----------*/
NULLIFERROR
NULLIFERROR(try_expression)
Description
Evaluates try_expression.
- If the evaluation of
try_expressiondoesn't produce an error, thenNULLIFERRORreturns the result oftry_expression. If the evaluation of
try_expressionproduces a system error, thenNULLIFERRORproduces that system error.If the evaluation of
try_expressionproduces an evaluation error, thenNULLIFERRORreturnsNULL.
Arguments
try_expression: An expression that returns a scalar value.
Return Data Type
The data type for try_expression or NULL
Example
In the following example, NULLIFERROR successfully evaluates
try_expression.
SELECT NULLIFERROR('a') AS result
/*--------*
| result |
+--------+
| a |
*--------*/
In the following example, NULLIFERROR catches an evaluation error in
try_expression.
SELECT NULLIFERROR(ERROR('a')) AS result
/*--------*
| result |
+--------+
| NULL |
*--------*/