Hey, I’m just getting started with dbt and was trying out marcos.
I get the error:
Syntax error: Unexpected “;” at [6:6]
though there is no ; in my code. Any assistance would be helpful
this is macro code:
{% macro macros_func(sales_amt) %}
SELECT AVG({{ sales_amt }}) AS average_salesamt
{% endmacro %}
Im calling it as:
select
transaction_id as trans_id,
{{ macros_func(‘sales_amount’) }} as amount_usd
from dbt_as.dbt_exc
Calling this way, your final dbt compiled code will be like
select
transaction_id as trans_id,
SELECT AVG(sales_amt) AS average_salesamt as amount_usd
from dbt_as.dbt_exc
It will take the SQL code in the macro and put it into your code.
If your macro is
{% macro macros_func(sales_amt) %}
AVG({{ sales_amt }})
{% endmacro %}
Then your compiled code will be
select
transaction_id as trans_id,
AVG(sales_amt) as amount_usd
from dbt_as.dbt_exc
Hi @brunoszdl , I made the changes and tried to run again but faced the same issue
Syntax error: Unexpected “;” at [6:1]
compiled Code at target/run/data_at_tyson_transformations/models/ananth_test/ananth_macros/macros_func.sql
06:45:20 1 of 1 ERROR creating sql view model dbt_as.macros_func … [ERROR in 1.45s]
06:45:20 Finished running node model.data_at_tyson_transformations.macros_func
Can you paste the compiled code?
It can be found under the <rproject_oot_folder>/target/compiled
folder