[英]How to create table manually or use postgres partition when using dbt?
我想使用 dbt 將數據插入到分區表中,但發現不支持 dbt postgres 分區。
通過另一種方式,我在 pre_hook 中創建表和分區,但在運行 dbt 時出現錯誤“關系‘download_counts_p’已經存在”
有什么建議嗎? 這是我的 SQL 和 pre_hook 配置
{{ config( materialized = 'table', indexes = [ ], pre_hook=[ 'CREATE TABLE IF NOT EXISTS "download_counts_p" ( "channel_id" int8 NOT NULL, "product_id" int8 NOT NULL, "country_code" text NOT NULL, "year" int2 NULL, "month" int2 NOT NULL, "count" int8 NOT NULL, "count" int8 NOT NULL, "months" int8 NOT NULL ) partition by list(country_code)', "DO $$ Declare unique_country_code varchar; BEGIN FOR unique_country_code IN SELECT country_code as unique_country_code FROM download_counts group by country_code LOOP EXECUTE format('create table IF NOT EXISTS download_counts_p_%s partition of download_counts_p for values in (''%s'')', upper(unique_country_code), unique_country_code); END LOOP; END; $$;"] )}} select 1
這里發生了一些不同的事情。
FOR... LOOP... END LOOP
掛鈎實際上應該使用 jinja 循環編寫為它自己的 model。 您可以使用run_query
宏將數據返回到神社上下文。 該頁面底部有一個示例,它將查詢結果提取到神社上下文中,然后使用{% for payment_method in results_list %}
循環遍歷它們
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.