length.md 2.1 KB


title: "LENGTH function" description: "Returns the number of characters in a string." menu: main:

parent: 'sql-functions'

LENGTH returns the code points in an encoded string.

Signatures

{{< diagram "func-length.svg" >}}

Parameter Type Description
str string or bytea The string whose length you want.
encoding_name string The 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

SELECT length('你好') AS len;
 len
-----
   2

SELECT length('你好', 'big5') AS len;
 len
-----
   3