为什么我会得到“意外”' &quot当我尝试运行DBT Jinja型号时,错误?

发布于 2025-02-09 08:59:57 字数 972 浏览 2 评论 0原文

我已经在DBT中创建了一个模型,以与雪花抗衡。我正在使用一些Jinja通过表名称列表进行迭代,并为每个表构建一些SQL。

以下脚本应遍历每个表,生成一些SQL脚本并在每个脚本之间插入一个联合语句,除了最后一次迭代。

我遇到以下错误,但是我看不到任何流浪括号

11:44:23 001003(42000):SQL汇编错误

11:44:23语法错误14在位置6出乎意料的第14号')'。

我的脚本是

{{
config(
    query_tag = 'DBT: Staging_History'  
)
}}

{% set table_names_query %}
select table_name
from information_schema.tables 
where table_type = 'BASE TABLE' and TABLE_CATALOG = 'PROD_SOURCE' and TABLE_SCHEMA = 
'DIS_STG'
{% endset %}

{% set results = run_query(table_names_query) %}

{% if execute %}
{% set results_list = results.columns[0].values() %}
{% else %}
{% set results_list = [] %}
{% endif %}


{% for table_name in results_list %}
SELECT * FROM TABLE(INFORMATION_SCHEMA.copy_history(table_name=>'PROD_SOURCE.DIS_STG.DBO_ORGANIZATION', start_time=>dateadd(DAY, -90, current_timestamp)))
{% if not loop.last %} UNION {% endif %}
{% endfor %}

I have created a model in DBT to run against Snowflake. I am using some jinja to iterate through a list of table names, and build some sql for each table.

The following script should loop through each table, generate some SQL script and insert a UNION statement between each piece of script except for the last iteration.

I am getting the following error however I can not see any stray parenthesis

11:44:23 001003 (42000): SQL compilation error

11:44:23 syntax error line 14 at position 6 unexpected ')'.

My script is

{{
config(
    query_tag = 'DBT: Staging_History'  
)
}}

{% set table_names_query %}
select table_name
from information_schema.tables 
where table_type = 'BASE TABLE' and TABLE_CATALOG = 'PROD_SOURCE' and TABLE_SCHEMA = 
'DIS_STG'
{% endset %}

{% set results = run_query(table_names_query) %}

{% if execute %}
{% set results_list = results.columns[0].values() %}
{% else %}
{% set results_list = [] %}
{% endif %}


{% for table_name in results_list %}
SELECT * FROM TABLE(INFORMATION_SCHEMA.copy_history(table_name=>'PROD_SOURCE.DIS_STG.DBO_ORGANIZATION', start_time=>dateadd(DAY, -90, current_timestamp)))
{% if not loop.last %} UNION {% endif %}
{% endfor %}

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

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

发布评论

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

评论(1

城歌 2025-02-16 08:59:57

如果要使用

因此以太更改为

current_timestamp()

CURRENT_TIMESTAMP

If you are going to use the macro of CURRENT_TIMESTAMP (aka without the parens) it must be in upper case.

So ether change to

current_timestamp()

or

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