Skip to content
Advertisement

How can I split a string into character in Snowflake?

I need to split a string like “abc” into individual records, like “a”, “b”, “c”.

This should be easy in Snowflake: SPLIT(str, delimiter)

But if the delimiter is null, or an empty string I get the full str, and not characters as I expected.

Advertisement

Answer

Update: SQL UDF


I found this problem while working on Advent of Code 2020.

Instead of just splitting a string a working solution is to add commas between all the characters, and then split that on the commas:

enter image description here

If you want to create a table out of it:

enter image description here

As seen on https://github.com/fhoffa/AdventOfCodeSQL/blob/main/2020/6.sql

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement