0
0
dbtdata~10 mins

Unique key for merge behavior 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 specify the unique key for merge behavior in a dbt model.

dbt
unique_key = "[1]"
Drag options to blanks, or click blank then click option'
Aid
Btimestamp
Cvalue
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-unique column like timestamp or name as the unique key.
2fill in blank
medium

Complete the code to define the merge strategy using the unique key in dbt.

dbt
merge_update = model.merge(on=[1])
Drag options to blanks, or click blank then click option'
A['timestamp']
B['name']
C['value']
D['id']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a non-unique column or forgetting to use a list.
3fill in blank
hard

Fix the error in the merge configuration by correctly specifying the unique key.

dbt
merge_config = {
  'unique_key': [1]
}
Drag options to blanks, or click blank then click option'
A'value'
B'id'
C'timestamp'
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-unique column or missing quotes around the key.
4fill in blank
hard

Fill both blanks to create a merge statement that uses the unique key and updates records.

dbt
merge_statement = model.merge(on=[1]).update([2])
Drag options to blanks, or click blank then click option'
A['id']
B{'status': 'active'}
C['timestamp']
D{'value': 100}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-list for the on parameter or wrong dictionary keys for update.
5fill in blank
hard

Fill all three blanks to define a merge with unique key, update columns, and insert columns.

dbt
merge_result = model.merge(on=[1]).update([2]).insert([3])
Drag options to blanks, or click blank then click option'
A['id']
B{'status': 'active'}
C{'id': 1, 'status': 'active', 'created_at': '2024-01-01'}
D{'value': 100}
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the update and insert dictionaries or using wrong keys.