2021-08-30

Snowflake - CSV field to rows

select 
    table_alias.*

    -- See how the field was split into several columns 
    -- (index, value, etc)
    , flattened_alias.*

    -- How to extract only the value
    , TRIM(flattened_alias.value::string) as "flattened_value"

from 

    "database_name"."schema_name"."table_name" as table_alias

    cross join

    lateral flatten(

        input => split(

            table_alias."csv_source_field_name", 

            ';' -- Separator

        ) 

    ) as flattened_alias

;

No comments:

Post a Comment