I've written some dbt macros, but the parameters aren't compiled at all when I run the project.
Consider this macro, for instance:
{% macro convert_to_timestamp(column_name) %}
try_cast({{ column_name }} as timestamp)
{% endmacro %}
I call it thus:
select
SMP,
{{ convert_to_timestamp(InicioPrev) }} as InicioPrev,
{{ convert_to_timestamp(FimPrevisao) }} as FimPrevisao
from {{ ref('src_smp_programado') }}
And it is compiled like so:
try_cast( as timestamp)
Is there something I'm missing?
You just need to use quotes (either single or double) around the column names when passing them as arguments to the macro. The same way you do it with ref
which is also a macro.
The following should compile to what you want it to.
select
SMP,
{{ convert_to_timestamp('InicioPrev') }} as InicioPrev,
{{ convert_to_timestamp("FimPrevisao") }} as FimPrevisao
from {{ ref('src_smp_programado') }}