length

Counts the Unicode characters in a string.

Syntax

length(<string>)

Arguments

ArgumentTypeDescription
<string>stringString to measure.

Returns

Returns int. Counts Unicode characters, not UTF-8 bytes. An empty string has length 0. Returns NULL if the input is NULL.

Examples

Measure the length of customer feedback, including text with non-ASCII characters.

VALUES ('call-17', 'Payment was slow'), ('call-42', '结账很慢')
SELECT $0 AS call_id, $1 AS feedback
SELECT call_id, feedback, length(feedback) AS characters
+---------+------------------+------------+
| call_id | feedback         | characters |
+---------+------------------+------------+
| call-17 | Payment was slow | 16         |
| call-42 | 结账很慢         | 4          |
+---------+------------------+------------+