【问题标题】:Storing the results from run query into a table in dbt将运行查询的结果存储到 dbt 中的表中
【发布时间】:2022-10-19 06:58:51
【问题描述】:

我在 dbt 中调用这个存储过程。如何使用 select 语句将结果存储到临时表中?

{% set results= run_query('call mystoredproc()') %}
 {% do log("Printing table" , info=True) %}
 {% do results.print_table() %}
 {% set sql %}
 select * from results <<--- how to store the result into  a temp table
{% end set %}  

 {% do run_query(create_table_as(True, tmp_relation, sql)) %}

【问题讨论】:

    标签: snowflake-cloud-data-platform dbt


    【解决方案1】:

    您应该使用物化,这是一种将 dbt 模型持久保存在仓库中的策略。您可以在 project.yml 文件中配置物化,也可以直接在 sql 文件中将其配置为:

    {{ config(materialized='table | view |', sort='timestamp', dist='user_id') }}
    
    select *
    from ...
    

    欲了解更多信息,请查看Materialization docs

    【讨论】:

      【解决方案2】:

      我在尝试创建以后可以在同一模型中加入的表时遇到了这个问题。原来我需要做的就是:

      with (call mystoredproc())
      as temp_table select ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-09
        • 1970-01-01
        • 2012-06-12
        • 2019-12-29
        • 1970-01-01
        • 1970-01-01
        • 2012-11-05
        • 1970-01-01
        相关资源
        最近更新 更多