Created
August 14, 2024 15:00
-
-
Save zelaznik/8ada258960e9b4a7f30e9c2bc42e42c8 to your computer and use it in GitHub Desktop.
Custom Agg Functions Notes
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
CREATE OR REPLACE FUNCTION my_count_state(state integer, value anyelement) | |
RETURNS integer AS $$ | |
BEGIN | |
IF value IS NOT NULL THEN | |
RETURN state + 1; | |
ELSE | |
RETURN state; | |
END IF; | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE OR REPLACE FUNCTION my_count_final(state integer) | |
RETURNS integer AS $$ | |
BEGIN | |
RETURN state; | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE AGGREGATE my_count(anyelement) ( | |
SFUNC = my_count_state, | |
STYPE = integer, | |
FINALFUNC = my_count_final, | |
INITCOND = '0' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment