Bird
0
0

Given a JSONB column info with value '{"location": {"city": "Boston"}}', why does the query

medium📝 Debug Q7 of 15
PostgreSQL - JSON and JSONB
Given a JSONB column info with value '{"location": {"city": "Boston"}}', why does the query
SELECT info #>> '{location,street}' FROM places; return NULL?
AThe operator #>> cannot be used with nested JSON paths
BThe key 'street' does not exist under 'location' in the JSON data
CThe JSON data is malformed
DThe query syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Analyze JSON structure

    The JSON contains 'location' with a 'city' key, but no 'street' key.
  2. Step 2: Understand #>> behavior

    The #>> operator returns NULL if the specified path does not exist.
  3. Final Answer:

    The key 'street' does not exist under 'location' in the JSON data -> Option B
  4. Quick Check:

    Check JSON keys at path [OK]
Quick Trick: Missing JSON key causes NULL with #>> [OK]
Common Mistakes:
  • Assuming #>> returns empty string if key missing
  • Thinking #>> fails on nested paths
  • Ignoring JSON structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes