Bird
0
0

Why does this query fail?

medium📝 Debug Q7 of 15
PostgreSQL - Advanced Features
Why does this query fail?

SELECT * FROM periods WHERE int_range <@ int4range('1,10');
Aint4range requires string input, not integers
Bint4range('1,10') is invalid syntax; use int4range('[1,10)')
Cint_range column is not a range type
DThe <@ operator is used incorrectly here
Step-by-Step Solution
Solution:
  1. Step 1: Check int4range constructor syntax

    The int4range(text) constructor expects a properly formatted string like '[1,10)', but '1,10' lacks bounds notation.
  2. Step 2: Correct usage

    Use int4range('[1,10)') or int4range(1,10).
  3. Final Answer:

    int4range('1,10') is invalid syntax; use int4range('[1,10)') -> Option B
  4. Quick Check:

    Range string needs bounds notation [OK]
Quick Trick: Construct ranges with string notation, not separate numbers [OK]
Common Mistakes:
  • Passing integers directly to int4range()
  • Misusing <@ operator
  • Assuming int4range is a function with numeric args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes