问题描述
我正在寻求有关在构建 ETL 模型时使用 Json 语法从 Postgres 迁移到 SNowFlake 的帮助
select
n.Object->c.name->>'some key in json file' as code
from names n
left join country c
你会如何在 SNowflake dbt 中写这个??
-- 更新: 在这里我会尽量解释得更好,因为这涉及 3 个表
1- 公司 2- 国家 3- 公司评级
为了方便起见,我们可以分别调用 A、B、C 列
公司表中的json列:
{
"AU": {},"CA": {},"GB": {
"company rating": "ijbfgp"
},"US": {},"ES": {
"company rating": "piayerb",},}
国家/地区表:
country name/code 列,所有国家/地区为 TEXT
公司评级表:
技术名称列,解释该评级是什么作为文本
我想做的是像在 postgres 中那样查询
company.A -> country.B ->> company.country_rating
解决方法
这是我可以根据您的描述重建的最好的:
with company as (
select parse_json('
{
"AU": {},"CA": {},"GB": {
"company rating": "ijbfgp"
},"US": {},"ES": {
"company rating": "piayerb",},}') x
),country as (
select 'GB' country_code,'Great Britain' country_name
union all select 'ES','Spain'
),ratings as (
select 'ijbfgp' rating_code,'incredible just before forgetting goal posts' rating
union all select 'piayerb','praying into abiss you exit running beach'
)
select country_name,rating
from company,country,ratings
where ratings.rating_code=get(x,country_code):"company rating"
在这种情况下导航 JSON 的关键是 get(x,country_code):"company rating"
。