Created
July 27, 2023 23:06
-
-
Save Arqentum/1f5b3e4cf19966d7ddf190fc184fbd57 to your computer and use it in GitHub Desktop.
#PSQL #SQL last_value_ignore_nulls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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