stored-procedures - 雪花存储过程从 dbt 失败
问题描述
我在通过 dbt 在 Snowflake 中执行存储过程时遇到问题:
我的过程的描述是这样的: MyStoredProcedure(ARRAY, VARCHAR, VARCHAR)
所以,当我想运行它时,我使用array_construct函数来创建第一个参数,例如:
call MyStoredProcedure(array_construct(array_construct('str_1', 'str_2')), 'schema_name', 'table_name');
这在我在雪花中运行时有效。但是,当我从 dbt 运行它时,它会因以下错误而失败:
不允许修改在不同范围开始的事务。
我确信这与在此调用中调用 array_construct 有关。
我应该提到,要从 dbt 运行它,我已经定义了一个这样的宏:
{% macro MyStoredProcedure() %}
{% set query -%}
CALL MyStoredProcedure(
array_construct(array_construct('str_1', 'str_2')),
'schema_name',
'table_name');
{%- endset %}
{% do run_query(query) %}
{% endmacro %}
当然像这样运行它:dbt run-operation MyStoredProcedure
我感谢任何提示或想法来帮助我解决这个问题。
谢谢
解决方案
我仍然非常了解雪花,但是通过阅读文档的这一部分 ,在我看来这可能只是您的多范围过程调用的机制。
据我所知,在雪花中执行此操作的典型(非 dbt)方法是:
begin transaction;
insert 1;
call storedprocedure();
insert 2;
commit;
也许您可以像这样调整宏,这将克服范围嵌套问题,因为一切都将在一个事务中完成?
{% macro MyStoredProcedure() %}
{% set query -%}
begin transaction;
CALL MyStoredProcedure(
array_construct(array_construct('str_1', 'str_2')),
'schema_name',
'table_name');
commit;
{%- endset %}
{% do run_query(query) %}
{% endmacro %}
无法对此进行测试,因为我无法重现该过程本身。
推荐阅读
- android - 如何观察发出回调请求的 ViewModel
- javascript - 键盘事件未按角度分派 Enter 键事件
- typescript - 递归/层次变换
- sql - 如何在Node.js中获取两个表数据,其中对象位于另一个对象中
- amazon-web-services - Dynamo AWS 表不允许我取消选中 DynamoDB JSON 以查看纯 JSON 中的对象
- azure - Azure 应用服务计划 - 分钟/天是什么意思?
- jquery - 捕捉到可滚动网站内容的“不可滚动”100vh 部分
- mongodb - 无法通过 mongoose 连接到 docker 上的 mongodb
- php - 如何根据不包含搜索词的 div 淡出动态生成的标题?
- python - 将 Flask 应用程序连接到 Websocket 服务器