Last active
June 3, 2016 09:04
-
-
Save bitdivine/49033ae7b7a92fe7ea0bc592fd325774 to your computer and use it in GitHub Desktop.
Postgres aggregator to get the first non-null value.
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
| -- Like the Postgres first_val() aggregator, exceppt that this returns the first non-null value. | |
| CREATE OR REPLACE FUNCTION first_non_null_fun(numeric, numeric) RETURNS numeric | |
| AS 'SELECT case when $1 is null then $2 else $1 end;' | |
| LANGUAGE SQL IMMUTABLE STRICT; | |
| CREATE AGGREGATE first_non_null ( numeric ) ( | |
| SFUNC = first_non_null_fun, | |
| STYPE = numeric | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment