Back to Materialize

LENGTH function

doc/user/content/sql/functions/length.md

1232.0 KB
Original Source

LENGTH returns the code points in an encoded string.

Signatures

{{% include-syntax file="examples/sql_functions/length" example="syntax" %}}

ParameterTypeDescription
strstring or byteaThe string whose length you want.
encoding_namestringThe encoding you want to use for calculating the string's length. Defaults to UTF-8.

Return value

length returns an int.

Details

Errors

length operations might return NULL values indicating errors in the following cases:

  • The encoding_name provided is not available in our encoding package.
  • Some byte sequence in str was not compatible with the selected encoding.

Encoding details

Examples

mzsql
SELECT length('你好') AS len;
nofmt
 len
-----
   2
<hr/>
mzsql
SELECT length('你好', 'big5') AS len;
nofmt
 len
-----
   3