Bird
0
0

Which is the correct way to pass a date string '2024-01-01' to the macro and use its result in a model?

hard📝 Application Q15 of 15
dbt - Jinja in dbt
You want to call a macro format_date from a project utils_project inside your project. You added utils_project in packages.yml. Which is the correct way to pass a date string '2024-01-01' to the macro and use its result in a model?
ASELECT {{ utils_project.format_date(`2024-01-01`) }} AS formatted_date
BSELECT {{ utils_project.format_date("2024-01-01") }} AS formatted_date
CSELECT {{ utils_project.format_date(2024-01-01) }} AS formatted_date
DSELECT {{ utils_project.format_date('2024-01-01') AS formatted_date }}
Step-by-Step Solution
Solution:
  1. Step 1: Confirm dependency is added

    utils_project is added in packages.yml, so macro can be called.
  2. Step 2: Check correct string passing in macro call

    Strings in Jinja macros should be double-quoted inside {{ }} to avoid syntax issues.
  3. Step 3: Validate SQL syntax

    SELECT {{ utils_project.format_date("2024-01-01") }} AS formatted_date correctly uses double quotes inside the macro call and proper SQL aliasing.
  4. Final Answer:

    SELECT {{ utils_project.format_date("2024-01-01") }} AS formatted_date -> Option B
  5. Quick Check:

    Double quotes for strings in macro calls = SELECT {{ utils_project.format_date("2024-01-01") }} AS formatted_date [OK]
Quick Trick: Use double quotes for string args inside {{ }} [OK]
Common Mistakes:
MISTAKES
  • Using unquoted strings causing errors
  • Incorrect SQL alias syntax
  • Missing quotes or wrong quote types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes