0
0
dbtdata~10 mins

Macros for reusable SQL logic in dbt - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a macro named 'get_active_users'.

dbt
{% macro [1]() %}
  SELECT * FROM users WHERE active = true
{% endmacro %}
Drag options to blanks, or click blank then click option'
Aget_active_users
Bactive_users
Cfetch_users
Dlist_active
Attempts:
3 left
💡 Hint
Common Mistakes
Using a macro name that does not match the task instruction.
Forgetting to include parentheses after the macro name.
2fill in blank
medium

Complete the code to call the macro 'get_active_users' inside a model.

dbt
SELECT * FROM {{ [1]() }}
Drag options to blanks, or click blank then click option'
Aget_active_users
Bfetch_active
Cactive_users
Dlist_active
Attempts:
3 left
💡 Hint
Common Mistakes
Using the macro name without parentheses.
Using a wrong macro name.
3fill in blank
hard

Fix the error in the macro call to correctly pass a parameter named 'status'.

dbt
SELECT * FROM {{ get_users(status=[1]) }}
Drag options to blanks, or click blank then click option'
A"active"
Bactive
C'active'
Dactive'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing string parameters without quotes causing syntax errors.
Using mismatched or double quotes incorrectly.
4fill in blank
hard

Fill both blanks to create a macro that accepts a parameter 'table_name' and returns a SELECT statement.

dbt
{% macro [1]([2]) %}
  SELECT * FROM {{ table_name }}
{% endmacro %}
Drag options to blanks, or click blank then click option'
Aselect_all
Btable_name
Ctable
Dget_table
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name different from the one used inside the macro body.
Forgetting parentheses around parameters.
5fill in blank
hard

Fill all three blanks to create a macro that filters a table by a given column and value.

dbt
{% macro [1]([2], [3]) %}
  SELECT * FROM {{ table }} WHERE {{ column }} = {{ value }}
{% endmacro %}
Drag options to blanks, or click blank then click option'
Afilter_table
Btable
Ccolumn
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching parameter names and variables inside the macro body.
Forgetting commas between parameters.