How can we pass column values to Macro for processing.
Example - in below model, we would like to pass column (col1,col2) values to macro (concat_macro) to process using these 2 columns .
with test as
(
select ‘abc’ as col1, ‘xyz’ as col2 union
select ‘ggg’ as col1, ‘xxx’ as col2
)select col1,col2,
{% if execute %}
‘{{ concat_macro(“col1”,“col2”) }}’ as column1 from test
{% endif %}
Regards,
Thanks @ joellabes for your reply…
Kindly find model and macro definition
macro
{% macro concat_macro(col1,col2) %}
{% set tmp = col1+col2 %}
{{ tmp }}
{% endmacro %}
Model
with test as
(
select ‘abc’ as col1, ‘xyz’ as col2 union
select ‘ggg’ as col1, ‘xxx’ as col2
)select col1,col2,
{% if execute %}
‘{{ concat_macro(“col1”,“col2”) }}’ as column1 from test
{% endif %}
I tried to remove the quotes from model but its giving error like invalid identifier ‘COL1COL2’
But Anyways if I just put quotes in model, out put model is giving like
COL1 COL2 COLUMN1
abc xyz col1col2
ggg xxx col1col2
Also Can you Please help me to understand when to use Macros and when to use Snowflake UDFs
Can you Please share some link/documentation for learning macros/jinja coding.
@joellabes - Appreciate your help
Regards,