Bird
0
0

Which of the following is the correct syntax to extract the JSON value of key 'name' as JSON from a column data in table users?

easy📝 Syntax Q12 of 15
PostgreSQL - JSON and JSONB
Which of the following is the correct syntax to extract the JSON value of key 'name' as JSON from a column data in table users?
ASELECT data->>name FROM users;
BSELECT data->>'name' FROM users;
CSELECT data->name FROM users;
DSELECT data->'name' FROM users;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct operator for JSON output

    To get the value as JSON, use -> with the key in single quotes.
  2. Step 2: Check syntax correctness

    Keys must be in quotes. Options C and D miss quotes around 'name'. SELECT data->>'name' FROM users; uses ->> which returns text, not JSON.
  3. Final Answer:

    SELECT data->'name' FROM users; -> Option D
  4. Quick Check:

    Use -> with quoted key for JSON [OK]
Quick Trick: Use single quotes around keys with -> or ->> [OK]
Common Mistakes:
  • Omitting quotes around JSON keys
  • Using ->> when JSON output is needed
  • Using invalid syntax like ->name without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes