Bird
0
0

You have a jsonb column with nested objects. You want to update a nested key without rewriting the entire JSON. Which function helps achieve this efficiently?

hard📝 Application Q9 of 15
PostgreSQL - JSON and JSONB
You have a jsonb column with nested objects. You want to update a nested key without rewriting the entire JSON. Which function helps achieve this efficiently?
Ajsonb_array_elements()
Bjsonb_set()
Cto_jsonb()
Djsonb_build_object()
Step-by-Step Solution
Solution:
  1. Step 1: Identify function for updating nested JSON keys

    jsonb_set() updates a value at a specified path inside a jsonb object.
  2. Step 2: Compare with other functions

    jsonb_array_elements() expands arrays, to_jsonb() converts data, and jsonb_build_object() builds new JSON objects, but none update nested keys efficiently.
  3. Final Answer:

    jsonb_set() -> Option B
  4. Quick Check:

    Update nested key function = A [OK]
Quick Trick: Use jsonb_set() to update nested JSON keys efficiently [OK]
Common Mistakes:
  • Using array functions to update objects
  • Rebuilding entire JSON instead of partial update
  • Confusing conversion functions with update functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes