Request a demo

BigQuery error · Data and type conversion

Integer Overflow (INT64)

An INT64 calculation went past the type's range (about 9.22 quintillion either way), and BigQuery fails the query instead of wrapping around. Large IDs or microsecond timestamps multiplied are typical. Cast to NUMERIC or BIGNUMERIC first, or use SAFE_ADD or SAFE_MULTIPLY to get NULL.

Error reason invalidQuery · HTTP 400 · Checked against the Google Cloud docs in November 2026

The error message

Integer Overflow

Causes

Arithmetic past the INT64 range

INT64 holds values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. +, -, * and ABS() past that range fail with Integer Overflow, for example UNIX_MICROS(ts) * 1000000 or multiplying a hash by a large constant.

SUM over many large values

Summing large INT64 values, such as byte counts or nanosecond durations over a long period, fails with Error in SUM aggregation: integer overflow.

Converting a large FLOAT64 to INT64

CAST(1e19 AS INT64) or CAST(POW(10, 19) AS INT64) fails with int64 out of range: 1e+19. A string that is too large reports Bad int64 value instead.

Hash values at the edge of the range

FARM_FINGERPRINT returns any INT64, including the minimum. ABS() or unary minus on that value overflows; unary minus reports int64 overflow: --9223372036854775808. Tools built on the open-source GoogleSQL engine word arithmetic overflow as int64 overflow: <a> + <b>.

How to fix it

1. Do the arithmetic in NUMERIC or BIGNUMERIC

Cast one operand first so the whole expression uses the wider exact type.

SELECT
  CAST(9223372036854775807 AS NUMERIC) + 1 AS plus_one,
  CAST(UNIX_MICROS(TIMESTAMP '2024-01-01') AS BIGNUMERIC) * 1000 AS unix_nanos;

2. Sum in NUMERIC

SUM of NUMERIC values has far more headroom than INT64.

SELECT SUM(CAST(bytes AS NUMERIC)) AS total_bytes
FROM UNNEST([9223372036854775807, 1]) AS bytes;

3. Return NULL instead of failing

SAFE_ADD, SAFE_SUBTRACT, SAFE_MULTIPLY and SAFE_NEGATE return NULL on overflow, and the SAFE. prefix works on functions such as ABS.

SELECT
  SAFE_ADD(9223372036854775807, 1) AS a,
  SAFE_MULTIPLY(5000000000000000000, 2) AS b,
  SAFE.ABS(-9223372036854775808) AS c;

4. Bucket hashes with MOD before ABS

For sampling or sharding with FARM_FINGERPRINT, take MOD first; the result's magnitude is always below the divisor, so ABS can't overflow.

SELECT ABS(MOD(FARM_FINGERPRINT('user_42'), 10)) AS bucket;

How to prevent it

  • Store counters that can grow without bound (bytes, nanoseconds, revenue in micros) as NUMERIC, or aggregate them in a larger unit.
  • Use SAFE_ arithmetic in data quality checks that run over untrusted data.
  • The query fails at run time, possibly after a long scan. On-demand it isn't billed; under capacity pricing the slots it used still count.

FAQ

Why doesn't BigQuery wrap around like C or Java?

GoogleSQL treats overflow as an error so silent wraparound can't corrupt results. Use NUMERIC, BIGNUMERIC, FLOAT64 or the SAFE_ functions when values may exceed INT64.

Will casting to FLOAT64 fix it?

It avoids the error but loses precision: FLOAT64 represents integers exactly only up to 2^53. Prefer NUMERIC or BIGNUMERIC for exact results.

How does INT64 compare with integer types in other databases?

It has the same range as BIGINT in PostgreSQL and MySQL. Snowflake's INTEGER is NUMBER(38,0) with a much larger range, so sums that fit in Snowflake can overflow in BigQuery. In BigQuery, INT, INTEGER, BIGINT, SMALLINT, TINYINT and BYTEINT are all aliases of INT64.

SQL reference

More data and type conversion

All BigQuery error messages · What 50M daily events say about BigQuery failures

Stop finding BigQuery failures in Slack threads

Masthead watches every BigQuery job, dbt model, Dataform action and Airflow task from audit logs, groups failures into incidents and shows which tables and dashboards are affected. No access to your data and no added BigQuery cost.