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.
{{< 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. |
length
returns an int
.
length
operations might return NULL
values indicating errors in the
following cases:
encoding
crate.
See the list of supported
encodings,
as well as their names within the
API.Materialize attempts to convert PostgreSQL-style encoding names into the WHATWG-style encoding names used by the API.
For example, you can refer to iso-8859-5
(WHATWG-style) as ISO_8859_5
(PostrgreSQL-style).
However, there are some differences in the names of the same encodings that
we do not convert. For example, the
windows-874 encoding is
referred to as WIN874
in PostgreSQL; Materialize does not convert these names.
SELECT length('你好') AS len;
len
-----
2
SELECT length('你好', 'big5') AS len;
len
-----
3