Debugging statements

GoogleSQL for BigQuery supports the following debugging statements.

ASSERT

ASSERT expression [AS description]

Description

Evaluatesexpression.

Ifexpression evaluates toTRUE, the statement returns successfullywithout any result.

Ifexpression evaluates toFALSE orNULL, the statement generates anerror. IfAS description is present,description will appear in the errormessage.

expression must evaluate to aBOOL.

description must be aSTRING literal.

AnASSERT statement is billed in the same way as the querySELECT expression, except that the result of anASSERT statement is nevercached.

Examples

The following examples assert that the data source contains more than a specificnumber of rows.

-- This query succeeds and no error is produced.ASSERT((SELECTCOUNT(*) >5FROMUNNEST([1,2,3,4,5,6])))AS'Table must contain more than 5 rows.';
-- Error: Table must contain more than 10 rows.ASSERT((SELECTCOUNT(*) >10FROMUNNEST([1,2,3,4,5,6])))AS'Table must contain more than 10 rows.';

The following examples assert that the data source contains a particular value.

-- This query succeeds and no error is produced.ASSERTEXISTS((SELECTXFROMUNNEST([7877,7879,7883,7901,7907])ASXWHEREX=7907))AS'Column X must contain the value 7907.';
-- Error: Column X must contain the value 7919.ASSERTEXISTS((SELECTXFROMUNNEST([7877,7879,7883,7901,7907])ASXWHEREX=7919))AS'Column X must contain the value 7919';

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-15 UTC.