Bird
0
0

You have a JSON column details with nested JSON: {"user": {"name": "Bob", "age": 25}}. Which query extracts the user's age as text?

hard📝 Application Q8 of 15
PostgreSQL - JSON and JSONB
You have a JSON column details with nested JSON: {"user": {"name": "Bob", "age": 25}}. Which query extracts the user's age as text?
ASELECT details->'user'->>'age' FROM table;
BSELECT details->>'user'->'age' FROM table;
CSELECT details->'user'->'age' FROM table;
DSELECT details->>'user'->>'age' FROM table;
Step-by-Step Solution
Solution:
  1. Step 1: Extract nested JSON object

    details->'user' extracts the nested JSON object under 'user'.
  2. Step 2: Extract 'age' as text

    Then ->>'age' extracts the 'age' field as text from that nested JSON.
  3. Final Answer:

    SELECT details->'user'->>'age' FROM table; -> Option A
  4. Quick Check:

    Use -> for JSON object, ->> for text extraction [OK]
Quick Trick: Chain -> for JSON, ->> for text at last step [OK]
Common Mistakes:
  • Using ->> too early in chain
  • Mixing -> and ->> incorrectly
  • Extracting JSON instead of text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes