I have macros get_date
{% macro get_date() %}
{% if execute %}
{% set p_date = run_query("select max(date) date from table" ).columns[0][0] %}
{% else %}
{% set p_date = '2024-04-01' %}
{% endif %}
{%do return(p_date)%}
{% endmacro %}
I call it in the model and then pass the variable to another macro
{% set my_date = get_date() %}
{{
config(
pre_hook=[
"{{ insert_table(report_date='" ~ my_date ~ "',pre_hook=True) }}"
]
)
}}
code of macro insert_table
{% macro insert_table(report_date,pre_hook=false) %}
{% if execute %}
insert into public.my_table
values ('{{report_date}}',current_timestamp,0)
{% endif %}
{% endmacro %}
When I run my model sql in marco get_date returns ‘2024-05-05’ in model my_date has value also ‘2024-05-05’ but in macro insert_table gets ‘2024-04-01’ and insert it into the table public.my_table.
I don’t understand why macro insert_table its gets ‘2024-04-01’ while it must gets ‘2024-05-05’. please Can someone explain what happens and what I do wrong ?
MADAO_MAN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.