From c050def2f389d43909fe13db140fd8a9c976898d Mon Sep 17 00:00:00 2001 From: nanimal-fb Date: Thu, 23 Jan 2025 16:09:53 -0800 Subject: [PATCH] string to array changes per PR 497 --- .../_includes/sql_examples/string_to_array.md | 41 +++++++++++++++++++ docs/_includes/sql_examples/vector_add.md | 2 +- .../_includes/sql_examples/vector_subtract.md | 2 +- .../string/string-to-array.md | 15 +++---- 4 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 docs/_includes/sql_examples/string_to_array.md diff --git a/docs/_includes/sql_examples/string_to_array.md b/docs/_includes/sql_examples/string_to_array.md new file mode 100644 index 000000000..d9d35676c --- /dev/null +++ b/docs/_includes/sql_examples/string_to_array.md @@ -0,0 +1,41 @@ +**Example** + +The following code example splits the string `stephen70|esimpson|ruthgill|` at each `|` character and returns the resulting array as `nicknames`: + +``` sql +SELECT STRING_TO_ARRAY('stephen70|esimpson|ruthgill|', '|') AS nicknames; +``` + +**Returns** + +| nicknames (ARRAY(TEXT)) | +| :--- | +| {stephen70,esimpson,ruthgill,""} | + +**Example** + +The following code example calls `STRING_TO_ARRAY` with an empty delimiter, producing an array containing a single element which contains the input text: + +``` sql +SELECT STRING_TO_ARRAY('firebolt', '') as size_one_array; +``` + +**Returns** + +| size_one_array (ARRAY(TEXT)) | +| :--- | +| {firebolt} | + +**Example** + +The following example calls `STRING_TO_ARRAY` with `NULL` as the delimiter, splitting the text into individual characters: + +``` sql +SELECT STRING_TO_ARRAY('firebolt', NULL) AS single_characters; +``` + +**Returns** + +| single_characters (ARRAY(TEXT)) | +| :--- | +| {f,i,r,e,b,o,l,t} | \ No newline at end of file diff --git a/docs/_includes/sql_examples/vector_add.md b/docs/_includes/sql_examples/vector_add.md index 6ef629499..11167d836 100644 --- a/docs/_includes/sql_examples/vector_add.md +++ b/docs/_includes/sql_examples/vector_add.md @@ -10,4 +10,4 @@ select vector_add([1, 2, 5], [3, 4, -2]) as res | res (ARRAY(BIGINT)) | | :--- | -| {4 | 6 | 3} | \ No newline at end of file +| {4,6,3} | \ No newline at end of file diff --git a/docs/_includes/sql_examples/vector_subtract.md b/docs/_includes/sql_examples/vector_subtract.md index 5a9e931cd..3d4341bbe 100644 --- a/docs/_includes/sql_examples/vector_subtract.md +++ b/docs/_includes/sql_examples/vector_subtract.md @@ -10,4 +10,4 @@ select vector_subtract([1, 5, 6], [3, 4, -2]) as res | res (ARRAY(BIGINT)) | | :--- | -| {-2 | 1 | 8} | \ No newline at end of file +| {-2,1,8} | \ No newline at end of file diff --git a/docs/sql_reference/functions-reference/string/string-to-array.md b/docs/sql_reference/functions-reference/string/string-to-array.md index 9f5a7af66..7d18a7d44 100644 --- a/docs/sql_reference/functions-reference/string/string-to-array.md +++ b/docs/sql_reference/functions-reference/string/string-to-array.md @@ -10,7 +10,10 @@ published: true # STRING_TO_ARRAY -This function splits a given string by a given separator and returns the result in an array of strings. +Splits a string into an array of strings based on a specified delimiter, with the following behaviors: + +* If the delimiter is an empty string `''`, the result is an array containing the entire original input string as a single element. +* If the delimiter is `NULL`, the string is split into individual characters, with one character per array element. ## Syntax {: .no_toc} @@ -29,13 +32,7 @@ STRING_TO_ARRAY(, ) ## Return Types `ARRAY(TEXT)` -## Example +## Examples {: .no_toc} -The following example splits the nicknames of players into separate items in an array: -```sql -SELECT - STRING_TO_ARRAY('stephen70|esimpson|ruthgill|', '|') AS nicknames; -``` - -**Returns**: `["stephen70","esimpson","ruthgill",""]` +{% include sql_examples/string_to_array.md %}