使用DBT创建表

发布于 2025-02-13 22:11:13 字数 52 浏览 1 评论 0原文

我们可以在DBT中创建新表吗? 我们可以使用DBT复制数据库中DEV环境中存在的表结构吗?

Can we create a new table in DBT?
Can we copy the table structure which is present in the dev environment in the database to another environment using DBT?

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

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

发布评论

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

评论(1

温柔戏命师 2025-02-20 22:11:14

是的。但是,DBT需要一个“原因”来创建表,例如,以实现其模型之一产生的数据。 DBT不能仅仅为了创建而创建表。

好吧,严格来说,您可以通过将创建表...放在前钩或hook hook 部分,但我想这不是您想要的,因为DBT在这里根本没有任何区别。

您可以在

{{ materialized="table" }}
select * 
from {{ source('your_source', 'existed_table_name') }}
limit 1 /* add "limit 1" if you only want the structure  */ 

将必要的连接凭据放在profiles.yml中,然后构建模型。在该模型表创建免费完成之前,DBT将从源表将一行从源表复制到模型表。

Yes. However, Dbt needs a "reason" to create tables, for example, to materialize the data produced by one of its models. DBT cannot create table just for the creation's sake.

Well, strictly speaking, you can do this by putting CREATE TABLE... in a pre-hook or post-hook section, but I suppose this is not what you want since dbt makes no difference here at all.

You can define your existed table in sources where you can set database, schema and table name different from the target storage space where dbt writes data. And then, define a model something like:

{{ materialized="table" }}
select * 
from {{ source('your_source', 'existed_table_name') }}
limit 1 /* add "limit 1" if you only want the structure  */ 

Put necessary connection credentials in the profiles.yml, and build the model. Dbt will copy one row from source table into model table, before that model table creation is done for free.

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