Docs/Metadata and operations/Common errors
Metadata and operationsOperations

Common BigQuery errors and how to fix them

This page explains the BigQuery error messages people hit most, such as "Unrecognized name", "neither grouped nor aggregated", "Cannot access field on a value with type ARRAY", "Resources exceeded" and "Query exceeded limit for bytes billed", and how to fix each one.

Practice this in free lessons on learn.querylab.io: Read the error and fix the query and 2 more.

Each error below was produced on BigQuery with the query shown, so the message is exactly what you will see. The position at the end, like at [6:8], is the line and column in your query. Errors in queries are free: a query that fails before it reads data isn’t billed. See How a query is billed.

This page is the short version. Many of these messages have a page of their own with every variant and fix, listed in BigQuery error messages.

Name and column errors

Unrecognized name

a column that doesn't existBigQuery rejects this query
12345678
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT customer, SUM(amount) AS total
FROM orders
GROUP BY customer
Error in BigQuery

Unrecognized name: customer; Did you mean customer_id? at [6:8]

The column, alias or table alias isn’t defined where you use it. BigQuery often suggests the closest name. Other causes: an alias defined in the same SELECT used in WHERE (aliases aren’t visible there), or a column that is inside a struct and needs the struct name in front. See Unrecognized name for every cause.

Table must be qualified with a dataset

FROM orders with no datasetBigQuery rejects this query
1
SELECT * FROM orders
Error in BigQuery

Table "orders" must be qualified with a dataset (e.g. dataset.table).

BigQuery needs dataset.table (or project.dataset.table), unless the job has a default dataset or you are in a script that created a temp table with that name. See Table must be qualified with a dataset and Projects, datasets and tables.

Table was not found in location

a misspelled public tableBigQuery rejects this query
1
SELECT * FROM `bigquery-public-data.samples.shakespear`
BigQuery dry run

Not found: Table bigquery-public-data:samples.shakespear was not found in location US

Either the name is wrong (table and dataset names are case-sensitive), you lack access, or the table exists but in a different location than the one the query runs in. See Table was not found in location, and for the same error on a dataset, Dataset was not found in location. A table you can’t read gives a different message: Access Denied: User does not have permission to query table.

Syntax error: Unexpected keyword

a reserved word as an aliasBigQuery rejects this query
1
SELECT 1 AS order
Error in BigQuery

Syntax error: Unexpected keyword ORDER at [1:13]

ORDER, GROUP, AT, ALL, END and other reserved words can’t be bare names. Quote them with backticks, AS `order`, or pick another name. See Syntax error: Unexpected keyword.

Column name is ambiguous

Two tables in the FROM clause have a column with the same name, and the query uses it without saying which table. The message is Column name customer_id is ambiguous. Put the table or alias in front of the column (o.customer_id), or join with USING. See Column name X is ambiguous.

Invalid field name

A column name was refused: Invalid field name "a.b". Fields must contain the allowed characters, and be at most 300 characters long. A dot, a dollar sign, a slash, a comma or a bracket is not allowed, and a name cannot start with _PARTITION, _TABLE_ or _FILE_. Spaces, hyphens and a leading digit are allowed. Rename the column. See Invalid field name.

Function not found

Function not found: UPPERR; Did you mean upper? at [1:8]. The name is a typo, a function from another dialect (DATEADD, NVL, GETDATE, LEN) or from legacy SQL, a user-defined function written without its dataset or in the wrong case, or a TEMP function created in a different query. A Did you mean name is a guess about spelling, so check what it does. See Function not found.

Duplicate column names

A plain query with two columns of the same name works, and BigQuery renames the second one to x_1. CREATE TABLE ... AS SELECT, CREATE VIEW and a query with a destination table refuse it, each with its own message, for example CREATE TABLE has columns with duplicate name id. SELECT * over a join is the usual cause. Name the columns. See Duplicate column names in the result.

Grouping errors

Neither grouped nor aggregated

order_id isn't groupedBigQuery rejects this query
12345678
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT customer_id, order_id, SUM(amount) AS total
FROM orders
GROUP BY customer_id
Error in BigQuery

SELECT list expression references column order_id which is neither grouped nor aggregated at [6:21]

Every selected column must be in GROUP BY or inside an aggregate like SUM or ANY_VALUE. Add it to GROUP BY (or use GROUP BY ALL), or aggregate it. If you want one whole row per group, use QUALIFY with ROW_NUMBER() instead of GROUP BY. See Neither grouped nor aggregated for all four variants of the message.

The same applies to ORDER BY after a GROUP BY:

ORDER BY a column that isn't groupedBigQuery rejects this query
123456789
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT customer_id, SUM(amount) AS total
FROM orders
GROUP BY customer_id
ORDER BY order_id
Error in BigQuery

ORDER BY clause expression references column order_id which is neither grouped nor aggregated at [9:10]

ARRAY in DISTINCT or GROUP BY

GROUP BY and SELECT DISTINCT accept a plain array. The error Column a of type ARRAY containing JSON cannot be used in SELECT DISTINCT means the array holds JSON or GEOGRAPHY. In PARTITION BY, ORDER BY, UNION DISTINCT and COUNT(DISTINCT ...) an array is refused. Group by TO_JSON_STRING(a) instead. See Column of type ARRAY cannot be used in SELECT DISTINCT.

Type errors

No matching signature for operator

an INT64 column compared with '30'BigQuery rejects this query
12345678
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT order_id
FROM orders
WHERE amount = '30'
Error in BigQuery

No matching signature for operator = for argument types: INT64, STRING Signature: T1 = T1 Unable to find common supertype for templated argument <T1> Input types for <T1>: {INT64, STRING} at [8:7]

BigQuery doesn’t convert strings to numbers for you, not even a string literal. Write the literal with the right type (30), or convert with CAST / SAFE_CAST. The same error appears when a STRING column meets a number:

a STRING column compared with 30BigQuery rejects this query
123456789
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
, typed AS (SELECT order_id, CAST(amount AS STRING) AS amount_text FROM orders)
SELECT order_id
FROM typed
WHERE amount_text = 30
Error in BigQuery

No matching signature for operator = for argument types: STRING, INT64 Signature: T1 = T1 Unable to find common supertype for templated argument <T1> Input types for <T1>: {INT64, STRING} at [9:7]

The Input types for <T1> line tells you which two types met. See No matching signature for operator and How BigQuery SQL differs.

No matching signature for function

The function exists, but not for the argument types or the number of arguments you gave it. The message lists every signature it tried and why each one failed. SUBSTR(order_id, 1, 2) on an INT64 column needs SUBSTR(CAST(order_id AS STRING), 1, 2). See No matching signature for function.

Cannot access field on an ARRAY

lines.sku on an array of structsBigQuery rejects this query
1234567
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT order_id, lines.sku
FROM orders
Error in BigQuery

Cannot access field sku on a value with type ARRAY<STRUCT<sku STRING, qty INT64>> at [6:24]

lines is an array, so it has no sku field; each of its elements does. Unnest the array and read the field from each element:

UNNEST first, then read the fieldOpen in Querylab.io
12345678
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT order_id, line.sku
FROM orders, UNNEST(lines) AS line
ORDER BY order_id
Result in BigQuery
Roworder_idsku
1o1apple
2o2pear
3o3plum
3 rows

See UNNEST and Cannot access field on a value with type ARRAY.

UNNEST values must be arrays

UNNEST of an INT64BigQuery rejects this query
1234567
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT x
FROM orders, UNNEST(amount) AS x
Error in BigQuery

Values referenced in UNNEST must be arrays. UNNEST contains expression of type INT64 at [7:21]

UNNEST takes an array. For a JSON array use UNNEST(JSON_QUERY_ARRAY(...)), and for a comma-separated string use UNNEST(SPLIT(s, ',')). The message names the type it got. See Values referenced in UNNEST must be arrays.

UNION column count

Every query in a UNION, INTERSECT or EXCEPT must return the same number of columns, matched by position. The message is Queries in UNION ALL have mismatched column count; query 1 has 3 columns, query 2 has 2 columns. Add the missing column, with NULL if you have no value, or use FULL OUTER UNION ALL BY NAME, which fills the missing column with NULL. See Queries in UNION ALL have mismatched column count.

Scalar subquery: more than one element

a subquery that returns two rowsBigQuery rejects this query
123456
WITH orders AS (
  SELECT 'c1' AS customer_id, 'o1' AS order_id, 30 AS amount, [STRUCT('apple' AS sku, 2 AS qty)] AS lines UNION ALL
  SELECT 'c1', 'o2', 45, [STRUCT('pear', 1)] UNION ALL
  SELECT 'c2', 'o3', 20, [STRUCT('plum', 6)]
)
SELECT (SELECT order_id FROM orders WHERE customer_id = 'c1') AS first_order
Error in BigQuery

Scalar subquery produced more than one element

A subquery used as a single value must return at most one row. Add a condition that makes it unique, aggregate (MAX(...), ARRAY_AGG(...)), or add LIMIT 1 with an ORDER BY if any one row will do. BigQuery doesn’t say which subquery failed. Querylab.io marks the ones in your query that can return more than one row. See Scalar subquery produced more than one element.

Correlated subqueries not supported

BigQuery rewrites a correlated subquery as a join, and fails with Correlated subqueries that reference other tables are not supported unless they can be de-correlated when it cannot. A LIMIT, an ORDER BY or a window function inside the subquery is the usual cause. Write it as a join with QUALIFY ROW_NUMBER() or ARRAY_AGG. See Correlated subqueries that reference other tables are not supported.

Errors from data values

These depend on the data, so a query can work for months and fail on the first bad row. Eight have their own pages: Bad int64 value, Failed to parse input string, Division by zero, UPDATE/MERGE must match at most one source row, Integer Overflow, Array cannot have a null element, Cannot parse regular expression and CSV or JSON table encountered too many errors.

MessageCauseFix
Bad int64 value: n/a (also Bad double value, Invalid NUMERIC value, Invalid date)a CAST of text that isn’t a valid valueSAFE_CAST, and find the bad rows; see SAFE functions
division by zero: 10 / 0dividing by zeroSAFE_DIVIDE(x, y)
Array cannot have a null element; error in writing field xan array with a NULL in the outputARRAY_AGG(x IGNORE NULLS); see Array cannot have a null element
Integer Overflow (also numeric overflow, Error in SUM aggregation: integer overflow, int64 out of range)a result outside the range of its typecast to NUMERIC first, or use SAFE_ADD and SAFE_CAST; see Integer Overflow
Cannot parse regular expression: invalid perl operator: (?=lookahead, lookbehind or a backreference; BigQuery uses RE2rewrite the pattern; see Cannot parse regular expression
CSV processing encountered too many errors, giving up (a load or an external table)more bad rows than max_bad_recordsread the failure details with bq show -j; see CSV or JSON table encountered too many errors
UPDATE/MERGE must match at most one source row for each target rowduplicate keys in the source of an UPDATE ... FROM or MERGEdeduplicate the source; see MERGE
Operands of = cannot be literal NULLx = NULLx IS NULL

Cost and quota errors

MessageCauseFix
Query exceeded limit for bytes billed: 1000000. 10485760 or higher required.the query would bill more than its maximum bytes billed settingread fewer columns or partitions, or raise the limit; see Controlling costs
Cannot query over table 'mydataset.orders' without a filter over column(s) 'order_date' that can be used for partition eliminationthe table has require_partition_filteradd a constant filter on the partitioning column; see Partitioning
Custom quota exceeded: Your usage exceeded the custom quota for QueryUsagePerDay (or QueryUsagePerUserPerDay)a per-project or per-user daily byte quota set by an adminwait for the next day or ask for a higher quota
Exceeded rate limits: too many table update operations for this tablemore than 5 metadata changes to one table in 10 seconds (loads, DDL, DML)retry with backoff; batch the writes
Your table exceeded quota for imports or query appends per tablemore than 1,500 loads or appends to one table in a daybatch files into fewer loads, or stream

Three of these have their own pages: Cannot query over table without a filter, Exceeded rate limits: too many table update operations and, for the free tier’s 1 TiB a month, Quota exceeded: free query bytes scanned.

Resources exceeded

This is the error for a query that ran out of memory or disk on a slot, not for one that was too expensive. The full message is Resources exceeded during query execution: <reason>, and the reason says why:

  • The query could not be executed in the allotted memory ... Top memory consumer(s): ORDER BY operations: a global ORDER BY on a large result, without LIMIT or with a large OFFSET. Sort less (ORDER BY ... LIMIT with no big OFFSET; page with ROW_NUMBER() instead), or don’t sort a result that is written to a table.
  • Not enough resources for query planning - too many subqueries or query is too complex: a query with very many CTEs, subqueries or views stacked on views. Split it into steps with temporary tables.
  • Your project or organization exceeded the maximum disk and memory limit available for shuffle operations: too much data moved between stages, often from a join that multiplies rows or from skewed keys. Filter and aggregate before joining; see Optimizing joins.

The usual fix is to change the shape of the query. Only the shuffle error also responds to capacity: Google suggests more reservation slots or fewer concurrent queries, and on-demand is capped at 2,000 slots per project. The execution graph shows which stage failed. The memory case has its own page: Resources exceeded: allotted memory.

Where to find the full error

In Querylab.io, dry-run errors appear in the status bar, and many of the errors above (an undefined column, a column that isn’t grouped, a missing partition filter) are underlined as you type (Code quality). The query history tab keeps failed jobs, and its search matches error text (Query history). The BigQuery console shows the message too. bq show -j <job_id> or INFORMATION_SCHEMA.JOBS (error_result) give the reason code too, such as invalidQuery, resourcesExceeded, quotaExceeded, usageQuotaExceeded, rateLimitExceeded or accessDenied. A rateLimitExceeded error is temporary and worth retrying. So is an internalError, unless the same query fails the same way every time. See An internal error occurred. The others need a change to the query or the setup.

See these errors flagged in the editor before the query runs. Open the playground. It is the real app on public datasets and needs no sign-in.