DBT的新手,并试图学习如何使用DBT执行过程,但要出错
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能在模型文件(模型目录中的任何.sql文件)中放置代码。 DBT假设模型文件包含一个
选择
语句;然后,它将选择
语句中的DDL(通常是创建表my_model as(...)
语句),具体取决于您对该模型的物质化配置。宏更灵活。通常,存储过程不是DBT工作流程的一部分,但是有一些有效的用例(以及UDFS)。
您可以在
宏
目录中创建utput_message.sql
文件,并使用提供的代码,将其包装在宏定义中,例如:您可以在:然后将其调用该宏post-hook或使用 run-operation :
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 thatselect
statement in DDL (usually acreate 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 yourmacros
directory, and use the code you provided, wrapping it in a macro definition, like:You can then call that macro in a post-hook or by using run-operation:
您可以使用“ 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.