Created
September 14, 2012 14:55
-
-
Save sycobuny/3722411 to your computer and use it in GitHub Desktop.
Cheap non-aggregate MAX() and AVG() functions
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 MYAVG(VARIADIC NUMERIC[]) | |
RETURNS NUMERIC | |
LANGUAGE SQL | |
AS 'SELECT AVG(unnest) FROM UNNEST($1)'; |
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 MYMAX(VARIADIC INTEGER[]) | |
RETURNS INTEGER | |
LANGUAGE SQL | |
AS 'SELECT MAX(unnest) FROM UNNEST($1)'; |
That is, to name them MYcrap() instead of just crap(). I'd go back and edit my comment but I suppose that's not possible? Or I'm an idiot.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sweet. Well, I suppose, absent any other evidence to the contrary, that it's not necessary to do MYAVG()/MYMAX() at all after all. That'd certainly make it syntactically prettier.