Request a demo

BigQuery · String function

BigQuery LEFT

LEFT(value, length) returns the first length characters of a string (or bytes of a BYTES value): LEFT('4111111111111111', 4) returns 4111. If the value is shorter, LEFT returns it whole; a negative length is an error.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

LEFT is a readable shortcut for SUBSTR(value, 1, length). For STRING it counts characters, for BYTES it counts bytes. A length of 0 returns an empty string, a length longer than the value returns the whole value, and NULL in either argument returns NULL.

The only failure mode is a negative length, which raises Second argument in LEFT() cannot be negative. This shows up when the length is computed, for example from STRPOS on a row where the delimiter is missing, so guard computed lengths.

For the end of a string, use RIGHT. For a slice in the middle, use SUBSTR.

Syntax

LEFT(value, length)

Arguments and return value

ArgumentDescription
valueThe STRING or BYTES value.
lengthINT64 number of characters (STRING) or bytes (BYTES) to return. Must not be negative.

Returns: STRING or BYTES, the same type as value.

Examples

Prefixes and short values

SELECT
  LEFT('4111111111111111', 4) AS card_prefix,
  LEFT('2026-11-23T08:15:00', 10) AS date_part,
  LEFT('EU', 5) AS shorter_than_length,
  LEFT('Zürich', 2) AS characters_not_bytes;
Result
card_prefixdate_partshorter_than_lengthcharacters_not_bytes
41112026-11-23EUZü

Group by a code prefix

WITH products AS (
  SELECT 'ELEC-1001' AS sku, 120 AS revenue UNION ALL
  SELECT 'ELEC-1002', 80 UNION ALL
  SELECT 'HOME-2001', 45
)
SELECT LEFT(sku, 4) AS product_line, SUM(revenue) AS revenue
FROM products
GROUP BY product_line
ORDER BY product_line;
Result
product_linerevenue
ELEC200
HOME45

Common mistakes

  • Computing a negative length. LEFT(email, STRPOS(email, '@') - 1) fails on rows without @ because STRPOS returns 0. Wrap it: IF(STRPOS(email, '@') > 0, LEFT(...), NULL).
  • Using LEFT on a number or date. LEFT(20261123, 4) fails with No matching signature; CAST to STRING first, or use EXTRACT for date parts.
  • Expecting padding. LEFT never adds characters to short values; use RPAD to force a fixed width.

FAQ

How do I get the first N characters of a string in BigQuery?

LEFT(value, n) or SUBSTR(value, 1, n). Both return the whole string when it is shorter than n.

Does BigQuery have LEFT and RIGHT functions?

Yes. LEFT(value, length) and RIGHT(value, length) work on STRING and BYTES.

How do I remove the first N characters?

Use SUBSTR(value, n + 1). For example, SUBSTR('INV-00042', 5) returns 00042.

Errors you may hit

More string functions

All BigQuery string functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.