Skip to content

OVERLAPS

(start_time TIMESTAMP, duration INTERVAL) OVERLAPS (other_start_time TIMESTAMP, other_duration INTERVAL)

Section titled “(start_time TIMESTAMP, duration INTERVAL) OVERLAPS (other_start_time TIMESTAMP, other_duration INTERVAL)”
  • start_time timestamp: This parameter specifies the starting time of the first period. It is a data type representing the date and time value.
  • duration interval: This parameter represents the length of the first period. It is specified as an interval data type, which represents a period of time.
  • other_start_time timestamp: This parameter represents the starting time of the second period. Like start_time TIMESTAMP, it is a data type that represents the date and time value.
  • other_duration interval: This parameter represents the length of the second period. Like duration INTERVAL, it represents a period of time and is specified as an interval data type.
CREATE TEMPORARY TABLE temp_table
(
start_date DATE,
end_date DATE
);
INSERT INTO temp_table
VALUES
('2000-01-01' , '2000-12-31'),
('2000-06-01' , '2001-06-01');
SELECT * FROM temp_table
WHERE (start_date, end_date) OVERLAPS ('2000-03-01'::date, '2000-09-01'::date);
start_date | end_date
------------+------------
2000-01-01 | 2000-12-31
2000-06-01 | 2001-06-01

In the above example, PostgreSQL OVERLAPS operator is used to determine if two time periods (defined by start date and end date) overlap with a specific time period. In this case, the given dates (‘2000-03-01’ and ‘2000-09-01’) overlap with the dates in the temporary table, hence both rows are returned in the output.