Bird
0
0

You wrote this query but it gives an error:

medium📝 Debug Q6 of 15
PostgreSQL - Advanced Features
You wrote this query but it gives an error:

SELECT * FROM bookings WHERE stay && '2023-01-01'::daterange;

What is the problem?
AThe column stay is not a range type
BThe right side should be a daterange, but '2023-01-01'::daterange is invalid
CThe && operator cannot be used with daterange types
DThe query is missing a JOIN clause
Step-by-Step Solution
Solution:
  1. Step 1: Check the cast on the right side

    Trying to cast a single date to daterange is invalid; a range needs two bounds.
  2. Step 2: Understand the correct usage

    To use &&, both sides must be ranges. You must provide a valid daterange, e.g. daterange('2023-01-01', '2023-01-02').
  3. Final Answer:

    The right side should be a daterange, but '2023-01-01'::daterange is invalid -> Option B
  4. Quick Check:

    Invalid cast to daterange causes error [OK]
Quick Trick: Cast to daterange with two bounds, not a single date [OK]
Common Mistakes:
  • Casting single date to daterange
  • Using && with non-range types
  • Assuming single date is a range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes