Amazon Redshift will no longer support the creation of new Python UDFs starting November 1, 2025.
If you would like to use Python UDFs, create the UDFs prior to that date.
Existing Python UDFs will continue to function as normal. For more information, see the
blog post
OCTET_LENGTH function
Returns the length of the specified string as the number of bytes.
Syntax
OCTET_LENGTH(expression)
Argument
- expression
-
A
CHARstring, aVARCHARstring, aVARBYTEexpression, or an expression that implicitly evaluates to aCHAR,VARCHAR, orVARBYTEtype.
Return type
- INTEGER
-
The OCTET_LENGTH function returns an integer indicating the number of bytes in the input string.
If the input string is a character 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 OCTET_LENGTH function will return12for that string, and the LEN function will return3for that same string.
Usage notes
If expression is a CHAR string, the function returns the length of the CHAR string. For example, the output of a CHAR(6) input is a CHAR(6).
If expression is a VARCHAR string, trailing spaces are counted.
Examples
To return the number of bytes when the string francais with three trailing spaces is cast to a CHAR and a VARCHAR type, use the following example. For more information, see the CAST function.
SELECT OCTET_LENGTH(CAST('francais ' AS CHAR(15))) AS octet_length_char, OCTET_LENGTH(CAST('francais ' AS VARCHAR(15))) AS octet_length_varchar;+-------------------+----------------------+ | octet_length_char | octet_length_varchar | +-------------------+----------------------+ | 15 | 11 | +-------------------+----------------------+
To return the number of bytes and the number of characters in
the string français, use the following example.
SELECT OCTET_LENGTH('français'), LEN('français');+--------------+-----+ | octet_length | len | +--------------+-----+ | 9 | 8 | +--------------+-----+
To return the number of bytes when the string français is cast as a VARBYTE, use the following example.
SELECT OCTET_LENGTH(CAST('français' AS VARBYTE));+--------------+ | octet_length | +--------------+ | 9 | +--------------+
Javascript is disabled or is unavailable in your browser.
To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.