Bird
0
0

You want to find all integer ranges in a table intervals with column int_range (type int4range) that do NOT overlap with [10, 20). Which query correctly finds these non-overlapping ranges?

hard📝 Application Q15 of 15
PostgreSQL - Advanced Features
You want to find all integer ranges in a table intervals with column int_range (type int4range) that do NOT overlap with [10, 20). Which query correctly finds these non-overlapping ranges?
ASELECT * FROM intervals WHERE NOT (int_range && int4range(10, 20));
BSELECT * FROM intervals WHERE int_range && int4range(10, 20);
CSELECT * FROM intervals WHERE int_range <@ int4range(10, 20);
DSELECT * FROM intervals WHERE int_range @> int4range(10, 20);
Step-by-Step Solution
Solution:
  1. Step 1: Understand the overlap operator &&

    && returns true if ranges overlap.
  2. Step 2: Find non-overlapping ranges

    To find ranges that do NOT overlap, negate the overlap condition with NOT (int_range && int4range(10, 20)).
  3. Final Answer:

    SELECT * FROM intervals WHERE NOT (int_range && int4range(10, 20)); -> Option A
  4. Quick Check:

    Negate overlap to find non-overlapping ranges [OK]
Quick Trick: Use NOT with && to find non-overlapping ranges [OK]
Common Mistakes:
  • Using && without NOT to find non-overlapping
  • Confusing <@ and @> operators
  • Using containment instead of overlap

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes