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

OCTET_LENGTH Function

Returns the length of the specified string as the number of bytes.

Syntax

Copy
OCTET_LENGTH(expression)

Argument

expression

The input parameter is a CHAR or VARCHAR text string.

Return Type

The OCTET_LENGTH function returns an integer indicating the number of bytes in the input string. The LEN function returns the actual number of characters in multi-byte strings, not the number of bytes. For example, to store three four-byte Chinese characters, you need a VARCHAR(12) column. 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.

Example

The following example returns the number of bytes and the number of characters in the string français.

Copy
select octet_length('français'), len('français'); octet_length | len --------------+----- 9 | 8 (1 row)