Bird
0
0

You have a JSONB column account with data:

hard📝 Application Q8 of 15
PostgreSQL - JSON and JSONB
You have a JSONB column account with data:
{"contact": {"phone": "9876543210", "email": "test@example.com"}}
Which query correctly extracts the phone number as text using path extraction?
ASELECT account ->> '{contact,phone}' FROM users;
BSELECT account #> '{contact,phone}' FROM users;
CSELECT account -> 'contact' ->> 'phone' FROM users;
DSELECT account #>> '{contact,phone}' FROM users;
Step-by-Step Solution
Solution:
  1. Step 1: Identify operator for text extraction

    The #>> operator extracts text at a specified path.
  2. Step 2: Verify path syntax

    The path {contact,phone} correctly targets the phone number.
  3. Step 3: Evaluate other options

    #> returns JSON, ->> does not accept path arrays, and ->> with path string is invalid.
  4. Final Answer:

    SELECT account #>> '{contact,phone}' FROM users; -> Option D
  5. Quick Check:

    Use #>> with path array for text [OK]
Quick Trick: Use #>> with path array to get text from JSONB [OK]
Common Mistakes:
  • Using #> instead of #>> for text
  • Incorrect path syntax with ->>
  • Confusing -> and ->> operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes