Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

sql - How to select variant column with one csv row as multiple columns in Snowflake?

I got a table TABVAR in snowflake which has column Var_Col which is VARIANT type. I load there each row from some csv, so values are like 'val1;val2;val3'.

I know that i can query it as columns directly from csv, but i have to do it other way.

The question is how to query Var_Col to obtain something like:

select firstValFromVar_Col, secondValFromVar_Col, thirdValFromVar_Col
from  TABVAR

I mean the query like above and result be like:

Col1 Col2 Col3
val1 val2 val3

Output of Select * from TABVAR :

Var_Col
val1;val2;val3
question from:https://stackoverflow.com/questions/65937740/how-to-select-variant-column-with-one-csv-row-as-multiple-columns-in-snowflake

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It can be done with:

select   split_part("Var_Col", ';',  1)
, split_part("Var_Col", ';',  2)
, split_part("Var_Col", ';',  3)
from "TABVAR"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...