Skip to main content

// advent-of-postgres/day-10

Day 10 of 24IntermediateRange typesSelf-joins

The Maintenance Windows

Two services in maintenance at the same time is how the night shift gets paged. Count the overlapping windows, and know what "touching" means for a range.

Opens 10 December 2026, 00:00 UTC

The rule is simple: two services should not be in maintenance at the same time. Bushy has the schedule for 10 December and a bad feeling about it.

The schedule is in maintenance:

Column Type Notes
id int Primary key
service text Who is doing maintenance
window_ tstzrange [start, end): the end is not included

A window that ends at 10:00 and another that starts at 10:00 only touch. They do not overlap. Two windows of the same service never count.

Your task

How many pairs of windows from different services overlap? Count each pair once.

Submit the number.

Stuck? Show a hint

&& is the overlap operator for ranges. Join the table to itself and keep each pair once.

No database yet. You get a real Postgres database on Neon, free, with no account.
One statement at a time. Ctrl+Enter or Cmd+Enter runs it.

Download today's data as SQL to solve it on your own Postgres (14 or later).

Solved this puzzle? Share it.

Tag @thedevopsdaily and share it with the community.