In the correct_code file, I am just hard coding the macro name under sql_text.
But in the wrong_code file, I am trying to pass the macro name to a variable and then using the variable name with the select command under sql_text block. So it should ne read as a macro (which is : select {{poc1_macro()) instead it is reading the whole thing as a variable itself and throwing an error:
syntax error line 1 at position 8 unexpected '{'.
syntax error line 1 at position 19 unexpected '('.
Hey @ashishk9, let me check I’m understanding you correctly:
You want to dynamically call a macro, by taking the name of a macro and surrounding it with curly braces (and parentheses for an empty function signature)?
This won’t work because dbt only goes through one rendering pass - as you’ve seen, the compiled result will just be the string {{poc1_macro()}} instead of whatever poc1_macro does.
Can you explain why you’re trying to do this? There might be a different approach you can take.
Hi @joellabes, I have three macros one which inserts data, one updates the table, and the last one is the main macro where I want to pass any of the two macros name as a parameter at a time. So that it performs only task which is insert or update.
I have gone through dbt fundamentals. My requirement here is to see whether I can call a macro in another macro or not? insert or update is just an option not my end result.
But when I try to call the macro as parameter, it reads that as a variable.
adapter.dispatch still requires the specific macro name to be specified in advance through a if/else block like your first example, i.e. you can’t do
{% set macro_name = 'my_macro' %}
{{ adapter.dispatch(macro_name)() }}
I am learning about sources in dbt. My understanding the sources define raw table location like database, schema, table name and so on, so we don’t hardcode the table name in the models (*.sql) . In the model I still define