Skip to content

Commit

Permalink
string to array changes per PR 497
Browse files Browse the repository at this point in the history
  • Loading branch information
nanimal-fb committed Jan 24, 2025
1 parent a578e09 commit c050def
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
41 changes: 41 additions & 0 deletions docs/_includes/sql_examples/string_to_array.md
Original file line number Diff line number Diff line change
@@ -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} |
2 changes: 1 addition & 1 deletion docs/_includes/sql_examples/vector_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ select vector_add([1, 2, 5], [3, 4, -2]) as res

| res (ARRAY(BIGINT)) |
| :--- |
| {4 | 6 | 3} |
| {4,6,3} |
2 changes: 1 addition & 1 deletion docs/_includes/sql_examples/vector_subtract.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ select vector_subtract([1, 5, 6], [3, 4, -2]) as res

| res (ARRAY(BIGINT)) |
| :--- |
| {-2 | 1 | 8} |
| {-2,1,8} |
15 changes: 6 additions & 9 deletions docs/sql_reference/functions-reference/string/string-to-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -29,13 +32,7 @@ STRING_TO_ARRAY(<string>, <delimiter>)
## 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 %}

0 comments on commit c050def

Please sign in to comment.