Stay organized with collectionsSave and categorize content based on your preferences.
GoogleSQL for BigQuery supports the following debugging statements.
ASSERT
ASSERT expression [AS description]
Description
Evaluatesexpression.
Ifexpressionevaluates toTRUE, the statement returns successfully
without any result.
Ifexpressionevaluates toFALSEorNULL, the statement generates an
error. IfAS descriptionis present,descriptionwill appear in the error
message.
expressionmust evaluate to aBOOL.
descriptionmust be aSTRINGliteral.
AnASSERTstatement is billed in the same way as the querySELECT expression, except that the result of anASSERTstatement is never
cached.
Examples
The following examples assert that the data source contains more than a specific
number 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';
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[[["\u003cp\u003e\u003ccode\u003eASSERT\u003c/code\u003e statements in GoogleSQL for BigQuery check if a given expression is true; if it is, the statement completes without issue, otherwise, it generates an error.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eASSERT\u003c/code\u003e statement includes an optional \u003ccode\u003eAS description\u003c/code\u003e clause, which allows for a custom message to be displayed in the error if the assertion fails.\u003c/p\u003e\n"],["\u003cp\u003eThe expression within an \u003ccode\u003eASSERT\u003c/code\u003e statement must evaluate to a boolean (\u003ccode\u003eBOOL\u003c/code\u003e) value, and the optional description must be a string literal (\u003ccode\u003eSTRING\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eASSERT\u003c/code\u003e statements are used to validate data, ensuring that it meets specific criteria, such as containing a certain number of rows or specific values.\u003c/p\u003e\n"],["\u003cp\u003eBilling for an \u003ccode\u003eASSERT\u003c/code\u003e statement is equivalent to the \u003ccode\u003eSELECT expression\u003c/code\u003e query, but the result is never cached.\u003c/p\u003e\n"]]],[],null,["# Debugging statements\n\nGoogleSQL for BigQuery supports the following debugging statements.\n\n`ASSERT`\n--------\n\n```\nASSERT expression [AS description]\n```\n\n**Description**\n\nEvaluates `expression`.\n\nIf `expression` evaluates to `TRUE`, the statement returns successfully\nwithout any result.\n\nIf `expression` evaluates to `FALSE` or `NULL`, the statement generates an\nerror. If `AS description` is present, `description` will appear in the error\nmessage.\n\n`expression` must evaluate to a `BOOL`.\n\n`description` must be a `STRING` literal.\n\nAn `ASSERT` statement is billed in the same way as the query\n`SELECT expression`, except that the result of an `ASSERT` statement is never\ncached.\n\n**Examples**\n\nThe following examples assert that the data source contains more than a specific\nnumber of rows. \n\n -- This query succeeds and no error is produced.\n ASSERT (\n (SELECT COUNT(*) \u003e 5 FROM UNNEST([1, 2, 3, 4, 5, 6]))\n ) AS 'Table must contain more than 5 rows.';\n\n -- Error: Table must contain more than 10 rows.\n ASSERT (\n (SELECT COUNT(*) \u003e 10 FROM UNNEST([1, 2, 3, 4, 5, 6]))\n ) AS 'Table must contain more than 10 rows.';\n\nThe following examples assert that the data source contains a particular value. \n\n -- This query succeeds and no error is produced.\n ASSERT\n EXISTS(\n (SELECT X FROM UNNEST([7877, 7879, 7883, 7901, 7907]) AS X WHERE X = 7907))\n AS 'Column X must contain the value 7907.';\n\n -- Error: Column X must contain the value 7919.\n ASSERT\n EXISTS(\n (SELECT X FROM UNNEST([7877, 7879, 7883, 7901, 7907]) AS X WHERE X = 7919))\n AS 'Column X must contain the value 7919';"]]