Bird
0
0

Given the table items with a json column data storing '{"a":1, "b":2}', what will this query return?

medium📝 query result Q13 of 15
PostgreSQL - JSON and JSONB
Given the table items with a json column data storing '{"a":1, "b":2}', what will this query return?
SELECT data @> '{"a":1}'::jsonb FROM items;
AError because <code>data</code> is json, but query uses jsonb operator
BTrue for rows where <code>data</code> contains key "a" with value 1
CFalse for all rows because <code>data</code> is json, not jsonb
DReturns all rows regardless of content
Step-by-Step Solution
Solution:
  1. Step 1: Understand operator compatibility

    The @> operator is defined for jsonb types, not for json. Using it on a json column causes an error.
  2. Step 2: Analyze the query

    The query tries to use @> on data which is json, but the right side is cast to jsonb. This mismatch causes a type error.
  3. Final Answer:

    Error because data is json, but query uses jsonb operator -> Option A
  4. Quick Check:

    jsonb operator on json column = Error [OK]
Quick Trick: jsonb operators need jsonb columns, not json [OK]
Common Mistakes:
  • Assuming json and jsonb are interchangeable
  • Ignoring type casting errors
  • Expecting operator to work on json type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes