Bird
0
0

Given run_started_at is a string '2024-06-01 10:00:00', which Jinja code correctly formats the table name?

hard📝 Application Q9 of 15
dbt - Jinja in dbt
You want to create a dynamic table name in dbt using the current model name and the run start date (YYYYMMDD). Given run_started_at is a string '2024-06-01 10:00:00', which Jinja code correctly formats the table name?
A{% set date = run_started_at.strftime('%Y%m%d') %} {{ this.name }}_{{ date }}
B{% set date = run_started_at[:10].replace('-', '') %} {{ this.name }}_{{ date }}
C{{ this.name }}_{{ run_started_at }}
D{{ this.name }}_{{ run_started_at[:10] }}
Step-by-Step Solution
Solution:
  1. Step 1: Extract date substring and remove dashes

    Since run_started_at is a string, slicing first 10 chars and replacing '-' works.
  2. Step 2: Concatenate model name and formatted date

    Using {{ this.name }}_{{ date }} creates the desired table name.
  3. Final Answer:

    {% set date = run_started_at[:10].replace('-', '') %} {{ this.name }}_{{ date }} -> Option B
  4. Quick Check:

    Use string slicing and replace for date formatting [OK]
Quick Trick: Use string slicing and replace to format dates in Jinja [OK]
Common Mistakes:
MISTAKES
  • Calling strftime on string
  • Using full timestamp without formatting
  • Ignoring date format requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes