[英]Postgres to Snowflake json syntax
我正在寻找使用 Json 语法从 Postgres 迁移到 SnowFlake 的帮助,同时构建 ETL model
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",
},
}
国家表:
国家名称/代码列,所有国家都为 TEXT
公司评级表:
技术名称列,用于解释该评级为 TEXT
我想做的是像在 postgres 中一样查询某事
公司.A -> 国家.B ->> 公司.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"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.