Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split single row value to multiple rows in Snowflake

I have a table where the column data has a combination of values seperated by ';'. I would like to split them into rows for each column value.

Table data enter image description here

Now I would like to split them into multiple rows for each value like

enter image description here

I have tried using the below SQL statement.

SELECT DISTINCT COL_NAME FROM "DB"."SCHEMA"."TABLE,
LATERAL FLATTEN(INPUT=>SPLIT(COL_NAME,';'))

But the output is not as expected. Attaching the query output below.

enter image description here

Basically the query does nothing to my data.

like image 617
Rajalakshmi Avatar asked May 02 '26 20:05

Rajalakshmi


1 Answers

It could be achieved using SPLIT_TO_TABLE table function:

This table function splits a string (based on a specified delimiter) and flattens the results into rows.

SELECT * 
FROM tab, LATERAL SPLIT_TO_TABLE(column_name, ';')
like image 157
Lukasz Szozda Avatar answered May 04 '26 12:05

Lukasz Szozda