首页 > 解决方案 > 我正在尝试通过 sql 访问雪花中的以下数据,但在列中获取 NULL。请调查一下

问题描述

下面是存储在表的一列中的数据(表:stg,col:LN)和我用来访问这些列的查询:

{"locations": [{"id": "893d7ef0", "name": "Organization", "type": "region"},
{"id": "7ad8787c", "name": "CORONA", "type": "st", "st_id": "1127"}]}

使用的查询是:

select * from(
               select
                   replace(LN : locations.id , '"' , '')as  loc_id,
                   replace(LN : locations.name , '"' , '') as loc_name,
                   replace(LN : locations.type , '"' , '') as loc_type,               
                   replace(LN : locations.st_id , '"' , '') as loc_store_id

           from db.schema.STG)

查询在列中给出 NULL,这就是问题所在。有什么建议么?

标签: sqlsnowflake-cloud-data-platform

解决方案


你可以试试这个吗?

select 
replace( j.value:id  , '"' , '')as  loc_id,
replace( j.value:name , '"' , '') as loc_name,
replace( j.value:type , '"' , '') as loc_type,               
replace( j.value:st_id , '"' , '') as loc_store_id
from STG, table(flatten ( LN, path => 'locations' )) j;    

推荐阅读