Goal: Prove inclusive and exclusive date boundaries, query historical availability, and compare relative dates and their types.
Connect to beer_db as student and make NULLs visible. You will query baked historical ranges and a separate three-row lesson_date_demo whose dates are seven days ago, today, and tomorrow when the lesson starts.
This keeps relative-date practice meaningful as the calendar changes; the course datasets remain unchanged.
List all 30 festivals with lower(held_during) as the included start and upper(held_during) as exclusive_end. The stored ranges use [start, end): the upper date is the first date outside the festival, not its last day. Sort by start, name, and ID. The 2023 Berliner Bierfest runs August 4 through August 9; its upper value is August 10.
Test the actual Berliner Bierfest range. lower_inc and upper_inc report whether each endpoint is included. August 9 is inside; August 10 is outside. Next compare a one-day range starting at exclusive_end with a range beginning one day earlier. Adding or subtracting an integer moves a date by whole days. The adjacent range does not overlap (f); the range sharing the final festival day does (t).
Use && to select festivals whose stored ranges share any date with [2023-01-01, 2024-01-01). The constructor daterange uses inclusive lower and exclusive upper bounds by default. Expect the 15 festivals overlapping 2023. A start-date-only test is a different question; a labelled cross-year range beginning in December 2022 still overlaps this window and returns t.
Use the real festival start, lower(held_during), for EXTRACT(year ...) and date_part(month ...). Preview three starts and their parts. These functions take an existing date; festivals has no premiere_date column. The supplied pg_typeof comparison reveals numeric for EXTRACT and double precision for date_part. Printed whole numbers can hide that type difference.
Inspect CURRENT_DATE and now(), plus their types: date versus timestamp with time zone. Their displayed values depend on the session clock and time zone; now() is the transaction-start instant. The provided event table contains last_week, today, and tomorrow.
Subtracting event_date from CURRENT_DATE produces day counts 7, 0, and -1. Compare a seven-day window with an exclusive upper date (only last_week) against BETWEEN, which includes today too. INTERVAL expresses a duration; adding an integer to a date retains date, while adding INTERVAL returns timestamp without time zone.
These are provided type and arithmetic comparisons, not production clock measurements.
Use the historical date DATE 2024-06-15 because the stored beer seasons belong to 2024. @> tests whether a range contains that date. Preview five of the 55 matching seasonal beers. Separately preview five missing ranges, shown as (NULL); there are 233 such beers.
For this report, explicitly include missing restrictions with OR IS NULL: the full count is 288. NULL alone does not prove year-round availability. A count query returns one aggregate row, not a one-beer result.
Switch to tv_db while keeping student as the read-only SQL role. This is a historical report as of 2025-06-15, not today. For plain date columns, both endpoints are inclusive: valid_from <= as-of date and valid_until >= it. This report also treats NULL valid_until as no end restriction.
The baked 300 rights have no NULL end dates, so a labelled three-row VALUES example makes the open-end case visible. VALUES creates a virtual table for this SELECT; its alias labels the columns. ends_today is active, expired is not, and open_end is active even though BETWEEN is unknown.
The provided JOIN uses sr for rights and s for shows, matching show_id to id to display titles; it previews Block 1.4. There are 300 qualifying rights, and LIMIT 15 displays only fifteen, ordered by title, region, platform ID, and unique right ID.