TEXT, LENGTH returns the number of characters (Unicode code points), not the number of bytes. A character whose UTF-8 encoding uses more than one byte still counts as one. For BYTEA, LENGTH returns the number of bytes. To count bytes in a TEXT value, use OCTET_LENGTH.
CHAR_LENGTH and CHARACTER_LENGTH are synonyms for LENGTH on TEXT.
When used with an array argument, LENGTH is a synonym for ARRAY_LENGTH
Syntax
Parameters
Return Type
INTEGER
Example
Use theLENGTH to find the length of any string, such as:
Rows: 1Execution time: 6.03ms
LENGTH counts characters rather than bytes, a multi-byte character counts as one. The character 🔥 is a single character encoded as four bytes (0xF0 0x9F 0x94 0xA5) in UTF-8:
Rows: 1Execution time: 5.44ms
LENGTH returns 1 for the single character, while OCTET_LENGTH returns 4 because its UTF-8 encoding uses four bytes.