Bird
0
0

Which of the following is the correct syntax to extract the JSON value of key 'age' as text from a column named 'data'?

easy📝 Syntax Q3 of 15
PostgreSQL - JSON and JSONB
Which of the following is the correct syntax to extract the JSON value of key 'age' as text from a column named 'data'?
ASELECT data->'age' FROM table_name;
BSELECT data->age FROM table_name;
CSELECT data->>'age' FROM table_name;
DSELECT data->>age FROM table_name;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct operator and syntax

    To extract the value as text, use ->> with the key as a string literal.
  2. Step 2: Check syntax correctness

    SELECT data->>'age' FROM table_name; uses data->>'age' correctly with quotes around 'age'. Options C and D miss quotes, causing syntax errors.
  3. Final Answer:

    SELECT data->>'age' FROM table_name; -> Option C
  4. Quick Check:

    Correct syntax = SELECT data->>'age' FROM table_name; [OK]
Quick Trick: Always quote JSON keys as strings in -> and ->> [OK]
Common Mistakes:
  • Omitting quotes around JSON keys
  • Using -> instead of ->> for text extraction
  • Using invalid syntax without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes