Bird
0
0

Given the table products with a json column details, what will be the result of this query?

medium📝 query result Q13 of 15
PostgreSQL - JSON and JSONB
Given the table products with a json column details, what will be the result of this query?
INSERT INTO products (details) VALUES ('{"color": "red", "size": "M"}');
SELECT details->>'color' FROM products WHERE details->>'size' = 'M';
A["M"]
B[null]
C["red"]
DEmpty result
Step-by-Step Solution
Solution:
  1. Step 1: Insert JSON with color and size keys

    The insert adds a row with details containing color: red and size: M.
  2. Step 2: Select color where size equals 'M'

    The SELECT filters rows where details->>'size' = 'M' and returns details->>'color', which is 'red'.
  3. Final Answer:

    ["red"] -> Option C
  4. Quick Check:

    Filter by size 'M' returns color 'red' [OK]
Quick Trick: Use ->> to get JSON text value for filtering and selecting [OK]
Common Mistakes:
  • Using -> instead of ->> returns JSON, not text
  • Expecting size value instead of color in output
  • Not matching the filter condition correctly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes