Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

LEN Function

Returns the length of the specified string.


LEN is a synonym of LENGTH Function, CHAR_LENGTH Function, CHARACTER_LENGTH Function, and TEXTLEN Function.




The input parameter is a CHAR or VARCHAR text string.

Return Type

The LEN function returns an integer indicating the number of characters in the input string. The LEN function returns the actual number of characters in multi-byte strings, not the number of bytes. For example, a VARCHAR(12) column is required to store three four-byte Chinese characters. The LEN function will return 3 for that same string.

Usage Notes

Length calculations do not count trailing spaces for fixed-length character strings but do count them for variable-length strings.


The following example returns the number of characters in the strings cat with no trailing spaces and cat with three trailing spaces:

select len('cat'), len('cat '); len | len -----+----- 3 | 6 (1 row)

The following example returns the ten longest VENUENAME entries in the VENUE table:

select venuename, len(venuename) from venue order by 2 desc, 1 limit 10; venuename | len ----------------------------------------+----- Saratoga Springs Performing Arts Center | 39 Lincoln Center for the Performing Arts | 38 Nassau Veterans Memorial Coliseum | 33 Jacksonville Municipal Stadium | 30 Rangers BallPark in Arlington | 29 University of Phoenix Stadium | 29 Circle in the Square Theatre | 28 Hubert H. Humphrey Metrodome | 28 Oriole Park at Camden Yards | 27 Dick's Sporting Goods Park | 26 (10 rows)