Debugging Statements in Standard SQL


ASSERT expression [AS description]


Evaluates expression.

If expression evaluates to TRUE, the statement returns successfully without any result.

If expression evaluates to FALSE or NULL, the statement generates an error. If AS description is present, description will appear in the error message.

expression must evaluates to a BOOL.

description must be a STRING literal.

An ASSERT statement is billed in the same way as the query "SELECT expression", except that the result of an ASSERT statement is never cached.


The following example asserts that the data source contains over five rows. The statement succeeds.

(SELECT COUNT(*) FROM UNNEST([1, 2, 3, 4, 5, 6])) > 5
AS 'Table must contain more than 5 rows.';

The following example asserts that the source table contains a particular value.

  FROM UNNEST([7877, 7879, 7883, 7901, 7907]) X
  WHERE X = 7919
) AS 'Column X must contain the value 7919';

The above statement generates this error:

Assertion failed: Column X must contain the value 7919