Skip to content

Instantly share code, notes, and snippets.

@Arqentum
Created July 27, 2023 23:06
Show Gist options
  • Select an option

  • Save Arqentum/1f5b3e4cf19966d7ddf190fc184fbd57 to your computer and use it in GitHub Desktop.

Select an option

Save Arqentum/1f5b3e4cf19966d7ddf190fc184fbd57 to your computer and use it in GitHub Desktop.
#PSQL #SQL last_value_ignore_nulls
do $transaction$
begin
create function coalesce_r_sfunc(state anyelement, value anyelement)
returns anyelement
immutable parallel safe
as
$$
select coalesce(value, state);
$$ language sql;
create aggregate last_value_ignore_nulls(anyelement) (
sfunc = coalesce_r_sfunc,
stype = anyelement
);
exception
when duplicate_function then null;
end
$transaction$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment