Search code examples
jinja2dbt

Jinja variables in function


I have defined a variable in jinja by using:

{% set my_var = 10 %}

And a macro by doing:

{% macro my_function(my_var) %}
    where my_col > my_var
{% endmacro %}

I want to call the macro on the variable I've set in order to obtain the string:

where my_col > 10

I've tried with

{{my_function(my_var)}}

but it doesn't work. I'm not sure if I have to change the call or the macro. Do you know how can I achieve this?

Thanks in advance!


Solution

  • There was a bug in the function definition, it needs to be defined like:

    {% macro my_function(my_var) %}
        where my_col > {{ my_var }}
    {% endmacro %}