BigQuery · String function
BigQuery ENDS_WITH
ENDS_WITH(value, suffix) returns TRUE if a string ends with suffix: ENDS_WITH(file_name, '.parquet') finds Parquet files. It is case-sensitive, treats every character literally and returns NULL for NULL input.
ENDS_WITH compares the end of value with suffix and returns a BOOL. The comparison is exact and case-sensitive, so ENDS_WITH('REPORT.CSV', '.csv') is FALSE. An empty suffix always returns TRUE, and NULL in either argument returns NULL.
It replaces LIKE '%suffix' without the wildcard pitfalls: % and _ inside the suffix are literal. Typical uses are file extensions, email domains (ENDS_WITH(email, '@example.com')) and naming conventions such as _backup tables.
For a case-insensitive check, lowercase the value first. To remove the suffix once you have found it, use LEFT(value, LENGTH(value) - LENGTH(suffix)) or an anchored REGEXP_REPLACE; RTRIM removes a set of characters and is the wrong tool.
Syntax
ENDS_WITH(value, suffix)Arguments and return value
| Argument | Description |
|---|---|
value | The STRING or BYTES value to test. |
suffix | The suffix to look for, the same type as value. |
Returns: BOOL. NULL if either argument is NULL.
Examples
Case sensitivity and edge cases
SELECT
ENDS_WITH('export_2026_11.parquet', '.parquet') AS parquet,
ENDS_WITH('REPORT.CSV', '.csv') AS case_sensitive,
ENDS_WITH(LOWER('REPORT.CSV'), '.csv') AS lowercased,
ENDS_WITH('REPORT.CSV', '') AS empty_suffix;| parquet | case_sensitive | lowercased | empty_suffix |
|---|---|---|---|
| true | false | true | true |
Users from one email domain, and stripping the suffix
Including the @ in the suffix keeps subdomains like sub.example.com out.
WITH users AS (
SELECT 'maria@example.com' AS email UNION ALL
SELECT 'li@sub.example.com' UNION ALL
SELECT 'tom@example.org'
)
SELECT
email,
LEFT(email, LENGTH(email) - LENGTH('@example.com')) AS user_name
FROM users
WHERE ENDS_WITH(email, '@example.com')
ORDER BY email;| user_name | |
|---|---|
| maria@example.com | maria |
Common mistakes
- Expecting case-insensitive matching.
ENDS_WITH(file, '.csv')misses.CSV; useENDS_WITH(LOWER(file), '.csv'). - Porting Snowflake's ENDSWITH. BigQuery spells it ENDS_WITH.
- Removing a suffix with RTRIM.
RTRIM('metrics.csv', '.csv')returnsmetribecause the second argument is a character set.
Cost and performance
- On a table with a search index, BigQuery can use the index for
ENDS_WITH(column, 'suffix'). ALIKE '%suffix'pattern isn't in the documented list of index-eligible predicates.
FAQ
How do I check if a string ends with a value in BigQuery?
Use ENDS_WITH(value, suffix). It returns TRUE, FALSE, or NULL when an argument is NULL.
What is the difference between ENDS_WITH and LIKE '%suffix'?
They match the same rows when the suffix has no % or _. ENDS_WITH treats those characters literally and is eligible for search index optimization.
Related
More string functions
All BigQuery string functions · All functions · BigQuery error messages
