LENGTH
Returns the number of characters in a string.
PostgreSQL 17.9
LENGTH(string)- string
- Source stringtext
Return value
An integer, the number of characters, not bytes
Examples
String length
PostgreSQL 17.9
SELECT LENGTH('PostgreSQL');Length of product names
PostgreSQL 17.9
SELECT good_name,
LENGTH(good_name) AS name_length
FROM Goods;Details
Unlike in MySQL, where LENGTH counts bytes, here it counts characters; the size in bytes is returned by OCTET_LENGTH. For the char(n) type, trailing spaces are not counted: LENGTH('ab '::char(5)) returns 2.