Accessing detailed error messages in BigQuery is essential for diagnosing and resolving issues encountered during query execution. This introduction elucidates the importance and methods of viewing detailed error messages in BigQuery, empowering users to troubleshoot effectively and optimize query performance.
BigQuery surfaces error information in a few different places, depending on whether a query fails before it even runs, fails partway through execution, or completes but produces a result you want to flag as invalid yourself. This covers all three.
As you type a query, the query editor checks it in the background. A red exclamation mark next to a line, and in the query validator at the bottom of the editor, means BigQuery has already spotted a problem, usually a syntax error, before you have even clicked Run. A green checkmark in the same spot means the query is valid and ready to execute. Catching an error here costs nothing, since the query never actually runs, whereas an error caught after clicking Run may have already used some processing time.
When a query does fail, the error response includes a reason code that tells you what category of problem you are dealing with. A few of the most common:
Knowing the category narrows down where to look immediately, rather than rereading the entire query line by line.
BigQuery surfaces error information in a few different places, depending on whether a query fails before it even runs, fails partway through execution, or completes but produces a result you want to flag as invalid yourself. This covers all three.
As you type a query, the query editor checks it in the background. A red exclamation mark next to a line, and in the query validator at the bottom of the editor, means BigQuery has already spotted a problem, usually a syntax error, before you have even clicked Run. A green checkmark in the same spot means the query is valid and ready to execute. Catching an error here costs nothing, since the query never actually runs, whereas an error caught after clicking Run may have already used some processing time.
When a query does fail, the error response includes a reason code that tells you what category of problem you are dealing with. A few of the most common:
Knowing the category narrows down where to look immediately, rather than rereading the entire query line by line.
In the console, open the menu, then go to BigQuery.
Open Menu > Bigquery

Click the three dots next to your project, then Create Dataset.

Give Dataset ID.
Click Create Dataset.

Click the three dots next to the dataset, then Open.

Click Create Table.

Choose Empty table as the source, give it a name, then click Create.

Click the three dots next to the table, then Open.

Click Compose new query, then paste in the following:
CREATE OR REPLACE TABLE business.customer AS
SELECT
123 AS cust_id,
“Evan” AS name;
SELECT * FROM business.customer;
Click Run.


Paste the following and click Run. It removes one row.
DELETE FROM business.customer WHERE true;

The ERROR function lets you fail a query deliberately, with your own message, when a result does not meet a condition you care about. Here, the query checks that the table has at least one row, and raises a custom error if it does not.
SELECT
COUNT(*) AS row_count
FROM business.customer
HAVING
IF(row_count > 0, true,
ERROR(FORMAT(“Error: row_count must be positive but it is %t”, row_count))
);
Click Run.

Since the table has no rows left after the delete, the condition fails and BigQuery displays the custom message you wrote inside FORMAT.

Most query failures are not a custom ERROR call, they are an ordinary mistake. When one happens, click Execution Details under the query results pane to see the full job information, including the specific error reason. For jobs you are checking after the fact, the Job History tab in BigQuery lists your recent jobs, and from the command line, bq show, followed by a job ID, returns the same detail, with bq show and the pretty json format option giving you the full error object for programmatic use.
That covers finding BigQuery’s own error details and raising a custom one with the ERROR function. To go further, explore Prwatech’s Google Cloud training program, which includes placement assistance.