Safely converts a BYTES value to a STRING, replacing any invalid UTF-8 characters with the Unicode replacement character instead of raising an error.
STRINGDiperbarui: 13 Jun 2026SAFE_CONVERT_BYTES_TO_STRING(bytes_value)The BYTES value to convert.
1 SELECT 2 SAFE_CONVERT_BYTES_TO_STRING(b'Hello World') as safe_string;
Convert valid bytes to a string.
1 SELECT 2 SAFE_CONVERT_BYTES_TO_STRING(b'Hello\xff\xfeWorld') as with_invalid;
Invalid characters are replaced with the Unicode replacement character.
1 -- CAST will error on invalid UTF-8 2 -- SELECT CAST(b'Hello\xff' AS STRING); -- Error! 3 4 -- SAFE_CONVERT does not error 5 SELECT SAFE_CONVERT_BYTES_TO_STRING(b'Hello\xff') as safe_result;
SAFE_CONVERT is more tolerant than CAST for invalid byte sequences.
Sudah paham SAFE_CONVERT_BYTES_TO_STRING? Latih langsung di browser
Latihan interaktif, langsung di browser.