Bird
0
0

Which of the following is the correct syntax to query a JSON field named data to get the value of key name in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - JSON and JSONB
Which of the following is the correct syntax to query a JSON field named data to get the value of key name in PostgreSQL?
ASELECT data->name FROM table_name;
BSELECT data['name'] FROM table_name;
CSELECT data.name FROM table_name;
DSELECT data->>'name' FROM table_name;
Step-by-Step Solution
Solution:
  1. Step 1: Recall JSON operators in PostgreSQL

    PostgreSQL uses ->> to get JSON text value by key.
  2. Step 2: Match correct syntax

    SELECT data->>'name' FROM table_name; uses data->>'name' which extracts the text value of key 'name'.
  3. Final Answer:

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

    JSON text extraction = ->> operator [OK]
Quick Trick: Use ->> to get JSON text value by key [OK]
Common Mistakes:
  • Using square brackets for JSON keys
  • Using dot notation for JSON keys
  • Using -> without quotes for key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes