Within Snowflake how could I split a string of data that's in a single field into multiple columns? This field is in a View and a type of Variant.
My View that I'm querying has 12 actual columns. 1 of those columns is a large string that I'd like to split into columns. One of the columns in the table is a key, so I'm trying to get the 6 attributes in the 1 column shown below into their own column. The string is made of column name and then value as you can see in the pattern. The data in the large string presents as shown below (changed actual names for corporate privacy reasons). I tried using SPLIT, but that didn't work as I needed. I appreciate the help.
FIELD NAME IN VIEW: MASTER_FIELD_PLAN_TYP
STRING IN VIEW'S FIELD:
{ "FIELD1_CD": "M", "FIELD1_CD_DESCR": "MEDICAL", "FIELD2_SRC_CD": "M", "FIELD2_SRC_CD_DESCR": "MEDICAL", "FIELD3_CD": "M","FIELD3_CD_DESCR": "MEDICAL", "FIELD4_SRC_CD": "M", "FIELD4_SRC_CD_DESCR": "MEDICAL", "FIELD5_CD": "MN", "FIELD5_CD_DESCR": "MINNESOTA", "FIELD6_ST_SRC_CD": "MN", "FIELD6_ST_SRC_CD_DESCR": "MINNESOTA" }
My attempt to make it look like a table in this area:
KEY | MASTER_FIELD_PLAN_TYP |
---|---|
58,502,601 | { "FIELD1_CD": "M1", "FIELD1_CD_DESCR": "MEDICAL1", "FIELD2_SRC_CD": "M2", "FIELD2_SRC_CD_DESCR": "MEDICAL2", "FIELD3_CD": "M3","FIELD3_CD_DESCR": "MEDICAL3", "FIELD4_SRC_CD": "M4", "FIELD4_SRC_CD_DESCR": "MEDICAL4", "FIELD5_CD": "MN5", "FIELD5_CD_DESCR": "STATE5", "FIELD6_ST_SRC_CD": "MN6", "FIELD6_ST_SRC_CD_DESCR": "STATE6" } |
I tried using SPLIT, but it created rows. I'd like to have in columns if possible.
EDIT... I added verbiage about the field being a type of Variant.