Debugging functions

GoogleSQL for Bigtable supports the following debugging functions.

Function list

NameSummary
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, returnsTRUE.
NULLIFERROR Evaluates a try expression, and if an evaluation error is produced, returnsNULL.

IFERROR

IFERROR(try_expression,catch_expression)

Description

Evaluatestry_expression.

Whentry_expression is evaluated:

  • If the evaluation oftry_expression doesn't produce an error, thenIFERROR returns the result oftry_expression without evaluatingcatch_expression.
  • If the evaluation oftry_expression produces a system error, thenIFERRORproduces that system error.
  • If the evaluation oftry_expression produces an evaluation error, thenIFERROR suppresses that evaluation error and evaluatescatch_expression.

Ifcatch_expression is evaluated:

  • If the evaluation ofcatch_expression doesn't produce an error, thenIFERROR returns the result ofcatch_expression.
  • If the evaluation ofcatch_expression produces 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 oftry_expression andcatch_expression must share asupertype.

Return Data Type

Thesupertype fortry_expression andcatch_expression.

Example

In the following example, the query successfully evaluatestry_expression.

SELECTIFERROR('a','b')ASresult/*--------+ | result | +--------+ | a      | +--------*/

In the following example,IFERROR catches an evaluation error in thetry_expression and successfully evaluatescatch_expression.

SELECTIFERROR(ERROR('a'),'b')ASresult/*--------+ | result | +--------+ | b      | +--------*/

In the following query, the error is handled by the innermostIFERRORoperation,IFERROR(ERROR('a'), 'b').

SELECTIFERROR(IFERROR(ERROR('a'),'b'),'c')ASresult/*--------+ | result | +--------+ | b      | +--------*/

In the following query, the error is handled by the outermostIFERRORoperation,IFERROR(..., 'c').

SELECTIFERROR(IFERROR(ERROR('a'),ERROR('b')),'c')ASresult/*--------+ | result | +--------+ | c      | +--------*/

In the following example,IFERROR catches an evaluation error inERROR('a')and then evaluatesERROR('b'). Because there is also an evaluation error inERROR('b'),IFERROR produces an evaluation error forERROR('b').

SELECTIFERROR(ERROR('a'),ERROR('b'))ASresult--ERROR:OUT_OF_RANGE'b'

ISERROR

ISERROR(try_expression)

Description

Evaluatestry_expression.

  • If the evaluation oftry_expression doesn't produce an error, thenISERROR returnsFALSE.
  • If the evaluation oftry_expression produces a system error, thenISERRORproduces that system error.
  • If the evaluation oftry_expression produces an evaluation error, thenISERROR returnsTRUE.

Arguments

  • try_expression: An expression that returns a scalar value.

Return Data Type

BOOL

Example

In the following examples,ISERROR successfully evaluatestry_expression.

SELECTISERROR('a')ASis_error/*----------+ | is_error | +----------+ | false    | +----------*/
SELECTISERROR(2/1)ASis_error/*----------+ | is_error | +----------+ | false    | +----------*/

In the following examples,ISERROR catches an evaluation error intry_expression.

SELECTISERROR(ERROR('a'))ASis_error/*----------+ | is_error | +----------+ | true     | +----------*/
SELECTISERROR(2/0)ASis_error/*----------+ | is_error | +----------+ | true     | +----------*/

NULLIFERROR

NULLIFERROR(try_expression)

Description

Evaluatestry_expression.

  • If the evaluation oftry_expression doesn't produce an error, thenNULLIFERROR returns the result oftry_expression.
  • If the evaluation oftry_expression produces a system error, thenNULLIFERROR produces that system error.

  • If the evaluation oftry_expression produces an evaluation error, thenNULLIFERROR returnsNULL.

Arguments

  • try_expression: An expression that returns a scalar value.

Return Data Type

The data type fortry_expression orNULL

Example

In the following example,NULLIFERROR successfully evaluatestry_expression.

SELECTNULLIFERROR('a')ASresult/*--------+ | result | +--------+ | a      | +--------*/

In the following example,NULLIFERROR catches an evaluation error intry_expression.

SELECTNULLIFERROR(ERROR('a'))ASresult/*--------+ | result | +--------+ | NULL   | +--------*/

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.