[英]Postgres to Snowflake json syntax
I am looking for help with migrating from Postgres to SnowFlake with Json syntax while building ETL model我正在寻找使用 Json 语法从 Postgres 迁移到 SnowFlake 的帮助,同时构建 ETL model
select
n.Object->c.name->>'some key in json file' as code
from names n
left join country c
How would you write this in Snowflake dbt??你会如何在 Snowflake dbt 中写这个?
-- update: Here i will try to explain better as this involves 3 tables -- 更新:这里我会尝试更好地解释,因为这涉及到3 个表
1- Company 2- Country 3- company rating 1- 公司 2- 国家 3- 公司评级
to make things easier we can call the columns A,B,C respectively为了方便起见,我们可以分别调用列 A、B、C
json column in company table :公司表中的 json 列:
{
"AU": {},
"CA": {},
"GB": {
"company rating": "ijbfgp"
},
"US": {},
"ES": {
"company rating": "piayerb",
},
}
Country table :国家表:
country name/code column with all countries as TEXT国家名称/代码列,所有国家都为 TEXT
Company rating table :公司评级表:
technical name column that explains what that rating is as TEXT技术名称列,用于解释该评级为 TEXT
What i am trying to do is query sth like in postgres我想做的是像在 postgres 中一样查询某事
company.A -> country.B ->> company.country_rating公司.A -> 国家.B ->> 公司.country_rating
This is the best that I could re-build from your description:这是我可以根据您的描述重建的最好的:
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"
The key to navigate the JSON in this case is get(x, country_code):"company rating"
.在这种情况下,导航 JSON 的关键是
get(x, country_code):"company rating"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.