Bird
0
0

Given a table orders with an integer array column product_ids and a GIN index on it, what does this query return?

medium📝 query result Q5 of 15
PostgreSQL - Indexing Strategies
Given a table orders with an integer array column product_ids and a GIN index on it, what does this query return?
SELECT * FROM orders WHERE product_ids @> ARRAY[101, 202];
AAll orders containing both product IDs 101 and 202 in the array
BOrders containing either product ID 101 or 202
COrders where product_ids array exactly matches [101, 202]
DOrders where product_ids array contains 101 but not 202
Step-by-Step Solution
Solution:
  1. Step 1: Understand the @> operator

    The @> operator checks if the left array contains the right array as a subset.
  2. Step 2: Interpret the query

    The query selects rows where product_ids contain both 101 and 202.
  3. Final Answer:

    All orders containing both product IDs 101 and 202 in the array -> Option A
  4. Quick Check:

    Does @> mean contains all elements? Yes. [OK]
Quick Trick: @> means 'contains all elements' in arrays [OK]
Common Mistakes:
  • Thinking @> means contains any element
  • Assuming exact array match
  • Confusing @> with overlap operator &&

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes