TRANSLATE
All functions > STRING > TRANSLATE
Returns a string with character-level replacements applied based on character-to-character mappings.
Signatures
Returns: String with character-level replacements applied
TRANSLATE(string: VARCHAR, from_chars: VARCHAR, to_chars: VARCHAR) → VARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to transform |
from_chars | VARCHAR | Yes | Characters to replace |
to_chars | VARCHAR | Yes | Characters to replace with (parallel mapping to from_chars) |
Notes
- Character-by-character replacement (not substring)
- Each character in from_chars maps to corresponding character in to_chars
- If to_chars is shorter, extra from_chars are deleted
- Order matters: first occurrence in from_chars takes precedence
Examples
FeatureQL
SELECT
f1 := TRANSLATE('12345', '123', 'ABC'), -- Replace digits with letters
f2 := TRANSLATE('Hello World', 'ol', 'OL'), -- Case change for specific chars
f3 := TRANSLATE('AABBCC', 'ABC', 'XYZ'), -- Multiple replacements
f4 := TRANSLATE('123-45-6789', '-', '.'), -- Replace dashes with dots
f5 := TRANSLATE('test', 'abcd', 'ABCD') -- No matching characters
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR |
|---|---|---|---|---|
| ABC45 | HeLLO WOrLd | XXYYZZ | 123.45.6789 | test |
On this page