Documentation

STRINGSPLIT

Stringsplit() function splits a string into multiple substrings based on a specified separator.

Syntax

stringsplit(expr,seperator,position)

Arguments

expr The input string to split. The argument expr is any expression of type string.

seperator A character or string that will be used to split the evaluated expression expr. seperator can be any expression of type string

position (optional) (Default value : 0) Substring to retrive from the resulting array of substrings. position can be any expression of type int.

Return Type

string

Return Value

stringsplit() returns the substring at the position, from the resulting array of substrings.

Remarks

None

Examples

A. Split strings and return second substring

create table segments
    (_id id, segment string);

insert into segments(_id,segment)
    values (1,'red,blue,green')

select _id, stringsplit(segment,',',1) as segment from segments;
+-----+----------+
| _id | segment  |
+-----+----------+
|   1 | blue     |
+-----+----------+

B. Split with a column as seperator.

create table segments
    (_id id, segment string, seperator);

insert into segments(_id, segment, seperator)
    values (1,'red,blue', ',')

insert into segments(_id, segment, seperator)
    values (2,'green:yellow', ':')

select _id, stringsplit(segment, seperator, 0) as segment from segments;
+-----+----------+
| _id | segment  |
+-----+----------+
|   1 | red      |
|   2 | green    |
+-----+----------+
Something missing or incorrect?
Help improve this article or join us on Discord!

© 2022 Molecula Corp. (DBA FeatureBase). All rights reserved.