DBT的新手,并试图学习如何使用DBT执行过程,但要出错

发布于 2025-02-02 17:09:30 字数 714 浏览 3 评论 0原文

create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
  return message;
end;

call output_message('Hello World');

错误:

Database Error in model my_first_dbt_model (models/example/my_first_dbt_model.sql)
  001003 (42000): SQL compilation error:
  syntax error line 2 at position 7 unexpected 'create'.

  syntax error line 3 at position 0 unexpected 'returns'.
  compiled SQL at target/run/dbt_project/example/my_first_dbt_model.sql

“获取此错误”

create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
  return message;
end;

call output_message('Hello World');

error I'm getting:

Database Error in model my_first_dbt_model (models/example/my_first_dbt_model.sql)
  001003 (42000): SQL compilation error:
  syntax error line 2 at position 7 unexpected 'create'.

  syntax error line 3 at position 0 unexpected 'returns'.
  compiled SQL at target/run/dbt_project/example/my_first_dbt_model.sql

getting this error

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

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

发布评论

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

评论(2

爱的那么颓废 2025-02-09 17:09:30

您不能在模型文件(模型目录中的任何.sql文件)中放置代码。 DBT假设模型文件包含一个选择语句;然后,它将选择语句中的DDL(通常是创建表my_model as(...)语句),具体取决于您对该模型的物质化配置。

更灵活。通常,存储过程不是DBT工作流程的一部分,但是有一些有效的用例(以及UDFS)。

您可以在目录中创建utput_message.sql文件,并使用提供的代码,将其包装在宏定义中,例如:

{% macro output_message(msg) %}
create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
  return message;
end;

call output_message(msg);
{% endmacro %}

您可以在:然后将其调用该宏post-hook或使用 run-operation

dbt run-operation output_message --args "{'msg': 'Hello World!'}"

You cannot put code for a stored procedure in a model file (any .sql file in your models directory). dbt assumes that a model file contains a single select statement; it then wraps that select statement in DDL (usually a create table my_model as (...) statement), depending on your materialization config for that model.

Macros are more flexible. Generally, Stored Procedures aren't part of the dbt workflow, but there are some valid use-cases for them (along with UDFs).

You can create a output_message.sql file in your macros directory, and use the code you provided, wrapping it in a macro definition, like:

{% macro output_message(msg) %}
create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
  return message;
end;

call output_message(msg);
{% endmacro %}

You can then call that macro in a post-hook or by using run-operation:

dbt run-operation output_message --args "{'msg': 'Hello World!'}"
傲性难收 2025-02-09 17:09:30

您可以使用“ href =” https://docs.getdbt.com/guides/guides/legacy/creating-new-new-materializations“ rel =“ nofollow noreferrer”> link 我遵循a < a href =“ https://docs.getdbt.com/guides/legacy/creating-new-materiasizations” rel =“ nofollow noreferrer”> link 创建DDL对象。您需要为此写宏。

You can customize your code using materialization link and I have followed a link to create ddl objects. You need to write macros for that.

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