Group by with a break on date I am trying to group data on homogenous periods of time (not sure this is clear).
Here is a simplified example of my data:
CREATE TABLE workhours_over_time (
             worker varchar,
             workhours integer,
             otherinfotobeignored varchar,
             startofperiod date,
             endofperiod date);

INSERT INTO workhours_over_time (worker, workhours, 
            otherinfotobeignored, startofperiod, endofperiod)
VALUES ('W1', '35', 'any info', '2020-01-01','2020-01-31');

INSERT INTO workhours_over_time (worker, workhours, 
            otherinfotobeignored, startofperiod, endofperiod)
VALUES ('W1', '35', 'any other info', '2020-02-01','2020-02-28');

INSERT INTO workhours_over_time (worker, workhours,
            otherinfotobeignored, startofperiod, endofperiod)
VALUES ('W1', '39', 'any info', '2020-03-01','2020-04-15');

INSERT INTO workhours_over_time (worker, workhours,
            otherinfotobeignored, startofperiod, endofperiod)
VALUES ('W1', '35', 'any info', '2020-04-16','2111-11-11');

So here is the result:
worker|workhours|otherinfotobeignored|startofperiod|endofperiod|
------|---------|--------------------|-------------|-----------|
W1    |       35|any info            |   2020-01-01| 2020-01-31|
W1    |       35|any other info      |   2020-02-01| 2020-02-28|
W1    |       39|any info            |   2020-03-01| 2020-04-15|
W1    |       35|any info            |   2020-04-16| 2111-11-11|

The result I need to obtain would group data in 3 periods: from 2020-01-01 to 2020-02-28, worker W1 works 35 hours a week. Then from 2020-03-01 to 2020-04-15 W1 works 39 hours a week. Then from 2020-04-16 to end of time, back to 35 hours.
worker|workhours|startofperiod|endofperiod|
------|---------|-------------|-----------|
W1    |       35|   2020-01-01| 2020-02-28|
W1    |       39|   2020-03-01| 2020-04-15|
W1    |       35|   2020-04-16| 2111-11-11|

I had first naive try with a simple group by:
select worker, workhours, min(startofperiod), max(endofperiod)
from workhours_over_time
group by worker, workhours

but of course, first and third period where grouped into a 2020-01-01 to 2111-11-11 period, which is not what I want.
Then I have toyed with window function, read on groups and island, but didn't find the solution...
Any idea ?
This is probably the most straightforward way to do this (edited to handle gaps):
SELECT
  Worker
 ,WorkHours
 ,startofperiod
 ,LEAD(priorend,1,'2111-11-11') OVER (Partition By Worker ORDER BY startofperiod) AS endofperiod
FROM
  (
    SELECT
      Worker
     ,startofperiod
     ,endofperiod
     ,LAG(endofperiod) OVER (PARTITION BY Worker ORDER BY startofperiod) AS priorend --Get prior end date in case of gap
     ,WorkHours
     ,CASE
        WHEN WorkHours &lt;&gt; LAG(WorkHours,1,-1) OVER (PARTITION BY Worker ORDER BY startofperiod) THEN 'Y'  --If hours change
        WHEN LAG(endofperiod + Interval '1 DAY') OVER (PARTITION BY Worker ORDER BY startofperiod) &lt;&gt; startofperiod THEN 'Y'  --If gap
        ELSE 'N'
      END AS Change_Ind
    FROM
      workhours_over_time
  ) summary
WHERE
  Change_Ind = 'Y'

Returns:
Worker  |   WorkHours   |   startofperiod   |   endofperiod
W1      |   35          |   2020-01-01      |   2020-02-29
W1      |   39          |   2020-03-01      |   2020-04-15
W1      |   35          |   2020-04-16      |   2111-11-11

This will handle gaps as long as your intervals are correct (in your example they are not as 2020 is a leap year).  You could change the logic to LAG(endofperiod + Interval '2 DAYS') OVER (PARTITION BY Worker ORDER BY startofperiod) &lt; startofperiod or just fix the end dates.