Window function? - Mailing list pgsql-general

From Robert Stanford
Subject Window function?
Date
Msg-id CAC1FqCEFtphM0EVZY01TA5TkSn8v8YdQRpXgasfmVYPtK-EsRw@mail.gmail.com
Whole thread Raw
Responses Re: Window function?  (Thiemo Kellner <thiemo@gelassene-pferde.biz>)
Re: Window function?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Window function?  (John W Higgins <wishdev@gmail.com>)
List pgsql-general
Hi,

I have time series data from multiple inputs with start and
end timestamps.

Can anyone suggest an elegant way to coalesce consecutive rows so only the 
first start time and last end time for each group of events (by input) is returned.

Sample from and to below where the rows for Input number 4 could be massaged.
(Timestamps selected with timestamp(0) for convenience)

From this:
Input   Start                 End                  
5       2022-06-04 09:09:00   2022-06-04 09:09:29
4       2022-06-04 09:08:50   2022-06-04 09:09:00
4       2022-06-04 09:08:10   2022-06-04 09:08:50
4       2022-06-04 09:07:47   2022-06-04 09:08:10
17      2022-06-04 09:06:47   2022-06-04 09:07:47
4       2022-06-04 09:06:37   2022-06-04 09:06:47
4       2022-06-04 09:06:29   2022-06-04 09:06:37
4       2022-06-04 09:06:17   2022-06-04 09:06:29
4       2022-06-04 09:05:53   2022-06-04 09:06:17
16      2022-06-04 09:04:33   2022-06-04 09:05:53

To this:
Input   Start                 End                  
5       2022-06-04 09:09:00   2022-06-04 09:09:29
4       2022-06-04 09:07:47   2022-06-04 09:09:00
17      2022-06-04 09:06:47   2022-06-04 09:07:47
4       2022-06-04 09:05:53   2022-06-04 09:06:47
16      2022-06-04 09:04:33   2022-06-04 09:05:53 

Thanks in advance to anyone who can help!
Robert

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: '{"x": 42, "y": null}'::jsonb != '{"x": 42}'::jsonb ... Really?
Next
From: Tim Kelly
Date:
Subject: Re: unoptimized nested loops