Bird
0
0

You have a JSON column profile with nested data:

hard📝 Application Q15 of 15
PostgreSQL - JSON and JSONB
You have a JSON column profile with nested data:
{"user": {"details": {"email": "user@example.com", "phone": "12345"}}}
Which query correctly extracts the email as text using the #>> operator?
ASELECT profile #>> 'user.details.email' FROM accounts;
BSELECT profile #> '{user,details,email}' FROM accounts;
CSELECT profile->'user'->'details'->>'email' FROM accounts;
DSELECT profile #>> '{user,details,email}' FROM accounts;
Step-by-Step Solution
Solution:
  1. Step 1: Understand the nested JSON path

    The email is nested under keys user, details, then email.
  2. Step 2: Use correct operator and path syntax

    #>> extracts text and requires path as an array in braces: '{user,details,email}'.
  3. Step 3: Evaluate other options

    #> returns JSON, not text; SELECT profile->'user'->'details'->>'email' FROM accounts; uses different operators but is valid syntax; SELECT profile #>> 'user.details.email' FROM accounts; uses incorrect path format.
  4. Final Answer:

    SELECT profile #>> '{user,details,email}' FROM accounts; -> Option D
  5. Quick Check:

    Use #>> with array path in braces for text extraction [OK]
Quick Trick: Use braces with comma-separated keys for #>> path [OK]
Common Mistakes:
  • Using dot notation inside quotes for path
  • Using #> instead of #>> for text
  • Confusing operator syntax with -> and ->>

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes