Request a demo

BigQuery · String function

BigQuery LENGTH

LENGTH(value) returns the number of characters in a STRING, or the number of bytes in a BYTES value. CHAR_LENGTH counts characters too; BYTE_LENGTH counts the UTF-8 bytes of a string, which differ for accented letters, non-Latin scripts and emoji.

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

LENGTH counts Unicode characters (code points) for STRING and bytes for BYTES. CHAR_LENGTH and CHARACTER_LENGTH are the same as LENGTH for strings. BYTE_LENGTH and its alias OCTET_LENGTH return the UTF-8 encoded size: 1 byte for ASCII, 2 for letters such as ï, up to 4 for emoji. For plain ASCII text all of them return the same number.

A code point is not always what a person sees as one character. A letter followed by a combining accent is two code points, and many emoji sequences are several. Normalize text with NORMALIZE (NFC) before you count if your data mixes composed and decomposed forms.

LENGTH returns 0 for an empty string and NULL for NULL, and it doesn't accept numbers or arrays: cast numbers to STRING, and use ARRAY_LENGTH for arrays. BigQuery has no LEN function.

Syntax

LENGTH(value)

CHAR_LENGTH(value)

CHARACTER_LENGTH(value)

BYTE_LENGTH(value)

OCTET_LENGTH(value)

Arguments and return value

ArgumentDescription
valueA STRING or BYTES value. CHAR_LENGTH and CHARACTER_LENGTH take STRING only.

Returns: INT64. NULL if value is NULL.

Examples

Characters vs bytes

SELECT
  LENGTH('naïve') AS length,
  CHAR_LENGTH('naïve') AS char_length,
  BYTE_LENGTH('naïve') AS byte_length,
  LENGTH('👍') AS emoji_length,
  BYTE_LENGTH('👍') AS emoji_bytes;
Result
lengthchar_lengthbyte_lengthemoji_lengthemoji_bytes
55614

Empty strings, NULLs and combining accents

'e\u0301' is e followed by a combining acute accent. NORMALIZE (NFC) composes it into the single character é.

SELECT
  LENGTH('') AS empty_string,
  LENGTH(CAST(NULL AS STRING)) AS null_string,
  LENGTH('e\u0301') AS decomposed_e_acute,
  LENGTH(NORMALIZE('e\u0301')) AS normalized;
Result
empty_stringnull_stringdecomposed_e_acutenormalized
0NULL21

Find values too long for a target column

Run this before loading into a system that limits names to 20 characters, or before casting to STRING(20).

WITH customers AS (
  SELECT 1 AS customer_id, 'Ana' AS display_name UNION ALL
  SELECT 2, 'Northwind Traders International Ltd'
)
SELECT customer_id, LENGTH(display_name) AS name_length
FROM customers
WHERE LENGTH(display_name) > 20
ORDER BY customer_id;
Result
customer_idname_length
235

Common mistakes

  • Using LENGTH to check byte limits. Systems that limit bytes (many databases, message queues, API fields) need BYTE_LENGTH; LENGTH('naïve') is 5 but the value takes 6 bytes.
  • Calling LEN or DATALENGTH from SQL Server, or LEN from Snowflake. BigQuery has neither; use LENGTH or BYTE_LENGTH.
  • Passing a number or an array. LENGTH(12345) fails with No matching signature; use LENGTH(CAST(n AS STRING)), and ARRAY_LENGTH for arrays.
  • Counting NULL as zero. LENGTH(NULL) is NULL, so WHERE LENGTH(col) = 0 misses NULL values; use WHERE IFNULL(col, '') = '' to find both.

Cost and performance

  • BigQuery bills on-demand queries by logical bytes read, and a STRING value counts as 2 bytes plus its UTF-8 size. SUM(BYTE_LENGTH(col) + 2) therefore estimates how much a column contributes to bytes scanned. See BigQuery pricing.

FAQ

What is the difference between LENGTH, CHAR_LENGTH and BYTE_LENGTH in BigQuery?

For STRING, LENGTH and CHAR_LENGTH both count characters. BYTE_LENGTH counts UTF-8 bytes. For BYTES values, LENGTH counts bytes.

How do I get the length of an array?

Use ARRAY_LENGTH. LENGTH only accepts STRING and BYTES.

Why does LENGTH count an emoji as more than one character?

LENGTH counts Unicode code points. Simple emoji are one code point, but flags, skin tones and family emoji are sequences of several code points.

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.