Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split one Row to Multiple Row Based on New line Character with Presto

Tags:

sql

presto

I have a table in Presto:

Table 1

I want:

Table 2

I have used UNNEST function with split function but I am not able to split each line using '\n' or char(10)

SELECT Col1,split_Col2 
FROM tbl
CROSS JOIN UNNEST(SPLIT(Col2,'\n')) AS t (split_Col2) 

does not work.

Even this:

SELECT Col1,split_Col2 
FROM tbl
CROSS JOIN UNNEST(SPLIT(Col2,char(10))) AS t (split_Col2) 

does not work.

I am very new to Presto and it would be great if someone could help!

like image 236
Scala_Beginner Avatar asked Dec 12 '25 17:12

Scala_Beginner


1 Answers

I think you meant to use the chr() function:

SELECT Col1,split_Col2 
FROM tbl
CROSS JOIN UNNEST(SPLIT(Col2,chr(10))) AS t (split_Col2) 
like image 53
Ike Walker Avatar answered Dec 15 '25 09:12

Ike Walker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!