Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to flatten Array string column to row in snowflake?

I’ve tried using snowflake’s flatten, but it doesn’t work, so I’m asking.

Example data

  • array string type -> varchar
id array string
1 [10001,100000][10003,100000000][10004,10000][10006,100]

I want

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

id array string
1 [10001,100000]
1 [10003,100000000]
1 …..

>Solution :

SELECT 
    id, 
    '[' || c.value::string AS "array string"
FROM data d,
     LATERAL FLATTEN(input=>split(d."array string", '[')) c;

should work, as you are splitting on the open array token, and thus need to put it back in the output.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading