- Categories:
String & binary functions (General) , Semi-structured and structured data functions (Conversion/Casting)
STRTOK_TO_ARRAY¶
Tokenizes the given string using the given set of delimiters and returns the tokens as an ARRAY value.
Syntax¶
STRTOK_TO_ARRAY( <string> [ , <delimiter> ] )
Arguments¶
Required:
string
Text to be tokenized.
Optional:
delimiter
Set of delimiters.
Default: A single space character.
Returns¶
This function returns a value of type ARRAY or NULL.
The function returns an empty array if tokenization produces no tokens.
If either argument is a NULL or JSON null value, the function returns NULL.
Examples¶
The following example uses the STRTOK_TO_ARRAY function to split a string into an array:
SELECT STRTOK_TO_ARRAY('a.b.c', '.') AS string_to_array;
+-----------------+
| STRING_TO_ARRAY |
|-----------------|
| [ |
| "a", |
| "b", |
| "c" |
| ] |
+-----------------+
The following example tokenizes on multiple delimiters (.
and @
):
SELECT STRTOK_TO_ARRAY('user@snowflake.com', '.@') AS multiple_delimiters;
+---------------------+
| MULTIPLE_DELIMITERS |
|---------------------|
| [ |
| "user", |
| "snowflake", |
| "com" |
| ] |
+---------------------+