Bird
0
0

Given a table orders with a JSON column details containing {"item":"book","qty":3}, what will this query return?

medium📝 query result Q4 of 15
PostgreSQL - JSON and JSONB
Given a table orders with a JSON column details containing {"item":"book","qty":3}, what will this query return?
SELECT details->>'item' FROM orders WHERE details->>'qty' = '3';
AReturns 'book' for rows where qty is 3.
BReturns NULL for all rows.
CReturns an error due to wrong operator.
DReturns '3' for all rows.
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSON operators used

    details->>'item' extracts text value of 'item'; details->>'qty' extracts text value of 'qty'.
  2. Step 2: Analyze WHERE clause condition

    WHERE details->>'qty' = '3' filters rows where qty equals string '3'.
  3. Final Answer:

    Returns 'book' for rows where qty is 3. -> Option A
  4. Quick Check:

    JSON text extraction and filtering works = returns matching rows [OK]
Quick Trick: Filter JSON text values with ->> operator in WHERE clause [OK]
Common Mistakes:
  • Expecting numeric comparison without quotes
  • Using -> instead of ->> for text extraction
  • Assuming query returns error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes