What is SPLIT() function in the Snowflake?

Are you looking to find what is the SPLIT() functions within the Snowflake cloud data warehouse or maybe you are looking for a solution about how to use the split functions in the Snowflake? Or may be you are looking for how to split string to column in the Snowflake. If you are looking for any of these problem solutions then you have landed on the correct page. I will also show you what and how to use SPLIT() function. I will explain the SPLIT() functions by taking a practical examples. So don’t waste time let’s start step by step guide to understand what is the SPLIT() expression in detail.

What is SPLIT() Function?

SPLIT() function is used to split a given string with the help of given separator and returns the result in an array of strings.

If contiguous split strings in the source string or the presence of the split string at the beginning or end of source string then results in empty string in the output. If the given separator is empty then the result will be same as source string.

Syntax of the Spit Function in Snowflake

-- Syntax : 

SPLIT( String, Separator )

SPLIT() Argument Details :

First Input Parameter String value ( Mandatory )
Second Input Parameter (Separator)String value ( Optional )
OutputArray of split string

First Input Parameter:

Text that need to be split into parts.

Second Input Parameter Separator:

Separator string based on which the input string will get split.

Output:

The data type of returned output is an ARRAY.

Example of SPLIT function in Snowflake:

--Example-1

select split('127.0.0.1', '.');

+-------------------------+
| SPLIT('127.0.0.1', '.') |
|-------------------------|
| [                       |
|   "127",                |
|   "0",                  |
|   "0",                  |
|   "1"                   |
| ]                       |
+-------------------------+

As we can see the above example splits the localhost IP address 127.0.01 into an array consisting of four parts.

--Example-2 :

select split('|a||', '|');

+--------------------+
| SPLIT('|A||', '|') |
|--------------------|
| [                  |
|   "",              |
|   "a",             |
|   "",              |
|   ""               |
| ]                  |
+--------------------+

As we can see the above example-2 which was split a string that contains vertical Pipe as separator ( Above output contains empty strings ).

Split Snowflake official Documentation Link

Final Thoughts

In this article we have learned about SPLIT() functions and uses with the examples explained clearly. I have also covered different scenario with practical example that could be possible. I hope the information that was provided is helped in gaining the knowledge.

Please share your comments and suggestions in the comment section below and I will try to answer all your queries as time permits.

Unicode in Snowflake

Repeat function in Snowflake

Leave a Comment