CODEPOINT_ARRAY

Updated at:

For a STRING or BINARY input, this function returns a BIGINT array. The array contains the Unicode code point of each character or the ASCII value of each byte in the input value.

Syntax

ARRAY CODEPOINT_ARRAY(STRING|BINARY|CHAR|VARCHAR <str>)

Parameters

str: Required. A value of the STRING, BINARY, CHAR, or VARCHAR type.

Return value

Returns a value of the ARRAY<BIGINT> type. The following rules apply:

  • If str is a STRING, CHAR, or VARCHAR, each element in the returned array is a code point. Each code point is in the range of [0, 0xD7FF] or [0xE000, 0x10FFFF].

  • If str is a BINARY, each element in the returned array is an extended ASCII value in the range of [0, 255].

  • If str is not a STRING, BINARY, CHAR, or VARCHAR, or if str is NULL, the function returns an error.

Examples

-- Returns [102,111,111].
SELECT CODEPOINT_ARRAY('foo');

-- Returns [102,111,111].
SELECT CODEPOINT_ARRAY(CAST('foo' AS CHAR(20)));

--Returns [104,101,108,108,111].
SELECT CODEPOINT_ARRAY(CAST('hello' AS VARCHAR(6500)));

-- Returns [102,111,111].
SELECT CODEPOINT_ARRAY(CAST('foo' AS BINARY));

-- An error is returned. FAILED: ODPS-0130071:[1,8] Semantic analysis exception - function CODEPOINT_ARRAY is ambiguous with (VOID), candidates are ARRAY<BIGINT> CODEPOINT_ARRAY(BINARY arg0); ARRAY<BIGINT> CODEPOINT_ARRAY(CHAR(255) arg0); ARRAY<BIGINT> CODEPOINT_ARRAY(STRING arg0); ARRAY<BIGINT> CODEPOINT_ARRAY(VARCHAR(65535) arg0
SELECT CODEPOINT_ARRAY(null); 

Related functions

CODEPOINT_ARRAY is a string function. For more information about functions that search for strings and convert string formats, see String Functions Overview.