Re: Window function?

2022-06-04 Thread Robert Stanford
On Sat, 4 Jun 2022 at 22:56, Thiemo Kellner wrote: > Hi Robert > > Interesting problem. I need to think about it. > > You need to figure out when Input changes. You can achieve this by using > lead or lag (depending of the sort direction over start) > https://www.postgresql.org/docs/current/funct

Window function?

2022-06-04 Thread Robert Stanford
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

Re: UUID vs serial and currval('sequence_id')

2022-05-02 Thread Robert Stanford
On Tue, 3 May 2022 at 08:39, David G. Johnston wrote: > You basically have to use "INSERT ... RETURNING" or variables. Which/how > depends on the language you are writing in. Pure SQL without client > involvement requires that you use chained CTEs of INSERT...RETURNING (or I > suppose you could

UUID vs serial and currval('sequence_id')

2022-05-02 Thread Robert Stanford
Hi, When doing an insert with a serial primary key we can refer to currval('sequence_name') in subsequent inserts and we also return it for later processing. Example: CREATE TABLE contact ( contactid serial not null primary key, -- creates sequence 'contact_contactid_seq' firstname text n