is_valid_utf8 function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 15.4 and later

Returns true if the input is a valid UTF-8 string, otherwise returns false.

Syntax

is_valid_utf8(strExpr)

Arguments

  • strExpr: A STRING expression.

Returns

A BOOLEAN, indicating whether the input STRING represents a valid UTF-8 string.

Examples

 Simple example taking a valid string as input.
> SELECT is_valid_utf8('Spark')
  true

 Simple example taking a valid collated string as input.
> SELECT is_valid_utf8('SQL' COLLATE UTF8_LCASE)
  true

 Simple example taking a valid hexadecimal string as input.
> SELECT is_valid_utf8(x'61')
  true

 Example taking an invalid hexadecimal string as input (illegal UTF-8 byte sequence).
> SELECT is_valid_utf8(x'80')
  false

- Example taking an invalid hexadecimal string as input (illegal UTF-8 byte sequence).
> SELECT is_valid_utf8(x'61C262')
  false