[英]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.