In the SQL snippet below, you see custom aggregates that are similar to first_value
/last_value
but which ignore NULL values, making them more useful in my opinion.
-- "s" stands for state, "v" stands for value, "sf" stands for state (transition) function
-- since these are defined as 'strict', "s" is the previous, while "v" is the next, non-null
-- value in the defined window.
create or replace function sf_first_value_ignore_nulls(s anyelement, v anyelement)