Challenge - 5 Problems
JSONB Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this JSONB update?
Given the table
data with a JSONB column info containing {"name": "Alice", "age": 30}, what is the result of this query?SELECT info || '{"age": 31, "city": "NY"}'::jsonb FROM data;Attempts:
2 left
💡 Hint
The || operator merges JSONB objects, replacing existing keys.
✗ Incorrect
The || operator merges two JSONB objects. If keys overlap, the right side's value replaces the left's. So 'age' changes from 30 to 31, and 'city' is added.
❓ query_result
intermediate2:00remaining
What does jsonb_set do in this query?
Consider a JSONB column
info with value {"user": {"name": "Bob", "age": 25}}. What is the output of:SELECT jsonb_set(info, '{user,age}', '26', false) FROM data;Attempts:
2 left
💡 Hint
jsonb_set replaces the value at the specified path with the new value.
✗ Incorrect
jsonb_set replaces the value at the path '{user,age}' with the new JSONB value "26" (string). The fourth argument false means it won't create missing keys.
📝 Syntax
advanced2:00remaining
Which option correctly removes a key from JSONB?
You want to remove the key
city from a JSONB column info. Which query is valid and works as expected?Attempts:
2 left
💡 Hint
The - operator removes a key from JSONB.
✗ Incorrect
The - operator removes a key from a JSONB object. jsonb_remove and jsonb_delete do not exist. The \ operator is invalid syntax.
❓ optimization
advanced2:00remaining
Best way to update nested JSONB key efficiently?
You have a large JSONB column
data with nested keys. You want to update settings.notifications.email to false for many rows. Which approach is most efficient?Attempts:
2 left
💡 Hint
jsonb_set updates nested keys without rewriting entire JSONB.
✗ Incorrect
jsonb_set efficiently updates nested keys by specifying the path. Extracting to text and replacing is slow and error-prone. Deleting entire keys loses data. jsonb_insert only inserts new keys, not update existing.
🧠 Conceptual
expert2:00remaining
What happens if jsonb_set tries to update a missing path with create_missing = false?
Given a JSONB column
doc with value {"a": {"b": 1}}, what is the result of:SELECT jsonb_set(doc, '{a,c}', '2', false) FROM data;Attempts:
2 left
💡 Hint
create_missing = false means do not create keys if path is missing.
✗ Incorrect
When create_missing is false and the path does not exist, jsonb_set returns the original JSONB unchanged without error.