Kdesl
1
I am very new to dbt… and trying to figure this out…
top of model:
{{config(
post_hook= [
"{{REMOVE_SAP_ACCRUAL_FILE()}},
“{{SAP_ACCRUAL_FILE()}}”
]
)}}
These are in the macros area of my project
Once the model runs, I want these 2 macros to run.
dbt run: am getting an error message ‘REMOVE_SAP_ACCRUAL_FILE’ is undefined.
Where do I define it so it gets recognized?
from project.yml:
macro-paths: [“macros”]
Based on the information you provided, your macro has to be in a .sql file in the dbt_project_root_folder/macros
Such as
dbt_project_root_folder/macros/remove_sap_accrual_file.sql
And inside the file the macro has to be defined inseide a macro statement like
{% macro REMOVE_SAP_ACCRUAL_FILE() %}
your macro code
{% endmacro %}
And I am not sure about case sensitivity in macro names
Kdesl
3
Thank you ! I didn’t end my macro names with “,sql”. My model has the following to call the macro:
and getting the error that SAP_ACCRUAL_FILE is undefined.
Can I not call 2 macros?
Kdesl
4
nevermind… I had the macro named as SAP_ACCRUAL_FILE,sql with a comma…
.sql is just the format of the file where you define your macros. But to call them you call like you were doing before
Calling the macro:
{{ REMOVE_SAP_ACCRUAL_FILE() }}
To define the macros (you can define more than one in a single file):
my_macros.sql
{% macro REMOVE_SAP_ACCRUAL_FILE() %}
your macro code
{% endmacro %}
{% macro SAP_ACCRUAL_FILE() %}
your macro code
{% endmacro %}
1 Like
Kdesl
6
Thank you for taking the time to respond. It is working perfectly now.