【发布时间】:2021-11-08 17:12:02
【问题描述】:
我一直试图在我的 SQL 模型中创建变量(由 Select 语句定义,而不是静态变量)但没有成功(试图模仿 SQL 存储过程中的 Declare/Set 语句)。我一直在使用调用语句函数来运行我的语句,然后使用 Set 将我的语句的结果分配给一个变量,但是无论我做什么,我都会收到配置中缺少变量或一些编译错误的错误。
尝试运行以下 IF 语句:
{%- call statement(name='get_last_snapshot_date', fetch_result=True) -%}
Select ifnull(max(snapshot_date),'9999-09-09') from my_data_source
{%- endcall -%}
{%- set data_last_snapshot_date = load_result('get_last_snapshot_date') -%}
{%- set last_snapshot_date = data_last_snapshot_date['data'][0][0] -%}
{%- call statement(name='get_current_date', fetch_result=True) -%}
Select current_date('GB')
{%- endcall -%}
{%- set data_get_current_date = load_result('get_current_date') -%}
{%- set current_snapshot_date = data_get_current_date['data'][0][0] -%}
{% if current_snapshot_date == last_snapshot_date: %}
Delete From my_data_source
Where snapshot_date = current_snapshot_date
{% endif %}
给我以下错误:
[2021-11-08 16:48:53,433] {pod_launcher.py:149} INFO - Compilation Error in model inventory_hist_test (models/inventory_hist_test.sql)
[2021-11-08 16:48:53,433] {pod_launcher.py:149} INFO - expected token ':', got '}'
[2021-11-08 16:48:53,433] {pod_launcher.py:149} INFO - line 29
[2021-11-08 16:48:53,434] {pod_launcher.py:149} INFO - {% if {{ current_snapshot_date }} == {{ last_snapshot_date }} %} (edited)
【问题讨论】:
标签: dbt