Bird
0
0

Given the table orders with a JSONB column details containing {"item": "book", "shipped": true}, what will the query SELECT * FROM orders WHERE details ? 'shipped'; return?

medium📝 query result Q4 of 15
PostgreSQL - JSON and JSONB
Given the table orders with a JSONB column details containing {"item": "book", "shipped": true}, what will the query SELECT * FROM orders WHERE details ? 'shipped'; return?
AAll rows where the value 'shipped' exists in details
BSyntax error due to incorrect operator usage
CNo rows, because 'shipped' is a boolean value
DAll rows where the key 'shipped' exists in details
Step-by-Step Solution
Solution:
  1. Step 1: Understand what the ? operator checks

    The operator checks if the key 'shipped' exists in the JSONB column.
  2. Step 2: Analyze the data and query

    The JSONB object has the key 'shipped', so the query returns rows where this key exists regardless of its value.
  3. Final Answer:

    All rows where the key 'shipped' exists in details -> Option D
  4. Quick Check:

    Key existence check returns matching rows [OK]
Quick Trick: ? operator checks keys, not values [OK]
Common Mistakes:
  • Thinking it checks values instead of keys
  • Assuming boolean values cause no match
  • Expecting syntax error incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes