Re: [SQL] Issues with lag command - Mailing list pgsql-sql

From David G. Johnston
Subject Re: [SQL] Issues with lag command
Date
Msg-id CAKFQuwYo0xNPRFpAoyd3r9wkuhT69oGfKY+c_6VEXZguYwdpkg@mail.gmail.com
Whole thread Raw
In response to Re: [SQL] Issues with lag command  (Steve Midgley <science@misuse.org>)
List pgsql-sql
On Fri, Jul 28, 2017 at 12:21 PM, Steve Midgley <science@misuse.org> wrote:

The general logic is that anytime we find a record with a time_id null, we would like to update it with the previous time_id that is not null.
I use the LAG function and the below code


​Lag can be made to work but only if you know that maximum lag that guarantees a non-null value is present.  If you cannot pick a reasonable number then you should write a custom aggregate function.  I believe I've seen posts (probably to -general) detailing this and you might find it in blog posts or the like as well.  I'm unable to provide a working example right now.

David J.

pgsql-sql by date:

Previous
From: Steve Midgley
Date:
Subject: Re: [SQL] Issues with lag command
Next
From: Igor Neyman
Date:
Subject: Re: [SQL] Issues with lag command