将运行查询的结果存储到DBT中的表中

发布于 2025-01-20 12:25:52 字数 374 浏览 3 评论 0原文

我在 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)) %}

I am calling this store procedure in dbt. How do I store the results using a select statement into a temp table?

{% 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)) %}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染年凉城似染瑾 2025-01-27 12:25:52

您应该使用实体化,这是持续仓库中DBT模型的策略。您可以在project.yml文件中配置实现化或直接在sql文件中配置它的内容:

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

select *
from ...

有关更多信息,请访问“物化文档”

You should use the materialization which is a strategy for persisting the dbt models in a warehouse. You can configure the materialization in the project.yml file or configure it directly inside the sql files as:

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

select *
from ...

For more info check the Materialization docs.

悍妇囚夫 2025-01-27 12:25:52

当我尝试创建一个稍后可以加入同一模型的表时,我遇到了这个问题。结果我需要做的就是:

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

I ran into this problem when trying to create a table that I could join later on in the same model. Turned out all I needed to do was:

with (call mystoredproc())
as temp_table select ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文