BigQuery · String function
BigQuery TRANSLATE
TRANSLATE(value, source_chars, target_chars) replaces each character in source_chars with the character at the same position in target_chars, and deletes source characters that have no counterpart: TRANSLATE(phone, '()- ', '') strips four characters in one call.
TRANSLATE works one character at a time. For each character of expression, it looks the character up in source_characters; if it is there, it is replaced by the character at the same position in target_characters, or removed when target_characters is shorter. Characters not in the source list are left alone. Extra characters at the end of target_characters are ignored.
Each character is translated at most once, so mappings don't chain: TRANSLATE('abc', 'ab', 'ba') swaps a and b and returns bac. A character listed twice in source_characters is an error. All three arguments must have the same type, STRING or BYTES, and NULL in any of them returns NULL.
TRANSLATE is the right tool for character-level cleanup: removing punctuation, mapping separators, or replacing a fixed list of accented letters. To replace whole words or multi-character sequences, use REPLACE; for classes of characters such as "everything that isn't a digit", use REGEXP_REPLACE.
Syntax
TRANSLATE(expression, source_characters, target_characters)Arguments and return value
| Argument | Description |
|---|---|
expression | The STRING or BYTES value to change. |
source_characters | The characters to replace or remove. No duplicates. |
target_characters | The replacement for each source character, by position. Source characters beyond its length are deleted. |
Returns: STRING or BYTES, the same type as expression.
Examples
Remove and map characters
SELECT
TRANSLATE('+1 (415) 555-0100', '()- ', '') AS removed,
TRANSLATE('2026/11/23', '/', '-') AS mapped,
TRANSLATE('Crème Brûlée', 'èûé', 'eue') AS accents,
TRANSLATE('abc', 'ab', 'ba') AS swapped;| removed | mapped | accents | swapped |
|---|---|---|---|
| +14155550100 | 2026-11-23 | Creme Brulee | bac |
Shorter and longer target lists
In shorter_target, - maps to . and _ has no counterpart, so it is deleted. In longer_target, the extra y is ignored.
SELECT
TRANSLATE('a-b_c', '-_', '.') AS shorter_target,
TRANSLATE('abc', 'a', 'xy') AS longer_target;| shorter_target | longer_target |
|---|---|
| a.bc | xbc |
Normalize product codes before a join
WITH supplier AS (
SELECT 'AB-12.7' AS supplier_code UNION ALL
SELECT 'CD 99/1'
)
SELECT supplier_code, UPPER(TRANSLATE(supplier_code, '-. /', '')) AS normalized_code
FROM supplier
ORDER BY supplier_code;| supplier_code | normalized_code |
|---|---|
| AB-12.7 | AB127 |
| CD 99/1 | CD991 |
Common mistakes
- Using TRANSLATE to replace words.
TRANSLATE(status, 'paid', 'done')maps the letters p, a, i, d to d, o, n, e everywhere in the string; use REPLACE for substrings. - Listing a character twice in the source.
TRANSLATE(s, 'aa', 'xy')fails withDuplicate character "a" in TRANSLATE source characters. - Expecting chained replacements. Each character is translated once, so mapping
atobandbtocturnsabintobc, notcc. - Trying to remove all accents with a short list. TRANSLATE only knows the characters you list; for general accent removal,
REGEXP_REPLACE(NORMALIZE(s, NFD), r'\pM', '')removes all combining marks.
FAQ
How do I remove several characters from a string at once in BigQuery?
Put them in the source list and pass an empty target: TRANSLATE(value, '()-. ', ''). Every listed character is deleted.
What is the difference between TRANSLATE and REPLACE?
REPLACE swaps whole substrings ('pie' to 'cake'). TRANSLATE maps single characters by position and can replace or delete many different characters in one pass.
Does BigQuery TRANSLATE work like Oracle and PostgreSQL TRANSLATE?
Yes for the core behaviour: characters map by position and source characters without a target are removed. BigQuery also raises an error for duplicate source characters.
Related
More string functions
All BigQuery string functions · All functions · BigQuery error messages
