Hey folks, I’m trying to create a macro that I call post hook at the end of my model run that does some dynamic updates after the fact. I have the update parameters in a separate table and the macro goes out and creates the update statements for the model then runs them one by one - not a set number of updates. If I call the macro through a run–operation and pass it the params it needs - no issue works great. If I drop it in post hook it fails on syntax.
below is the macro code.
{% macro post_hook_enum(schema_name, table_name) %}
{% set query %}
SELECT enum_update_query
FROM {{ source('static_stage','enum_updates') }}
WHERE schemaname = '{{ schema_name }}'
AND tablename = '{{ table_name }}'
{% endset %}
{{ log(query, info=True) }}
{% set enum_update_query = run_query(query) %}
{% if enum_update_query %}
{% for row in enum_update_query %}
{{ log(row[0], info=True) }}
{% set curr_query = row[0] %}
{{ log("Query to be executed:", curr_query) }}
{{ run_query(curr_query) }}
{{ log("Query executed successfully.", info=True) }}
{% endfor %}
{% else %}
{{ log("No enum update queries found.", info=True) }}
{% endif %}
{% endmacro %}
Fail notice
:10 1 of 1 ERROR creating sql table model finance_stage.Dim_AFE2 … [ERROR in 38.27s]
22:37:10
22:37:10 Finished running 1 table model in 0 hours 0 minutes and 47.84 seconds (47.84s).
22:37:10
22:37:10 Completed with 1 error and 0 warnings:
22:37:10
22:37:10 Runtime Error in model Dim_AFE2 (models\common_stage\Dim_AFE2.sql)
22:37:10
22:37:10 [PARSE_SYNTAX_ERROR] Syntax error at or near ‘|’.(line 18, pos 12)
Any thoughts?