Skip to content

Instantly share code, notes, and snippets.

@iangow
Created May 7, 2016 20:37
Show Gist options
  • Save iangow/4bc239486174330fd4d6b88d98bfe9f6 to your computer and use it in GitHub Desktop.
Save iangow/4bc239486174330fd4d6b88d98bfe9f6 to your computer and use it in GitHub Desktop.
Function to add median aggregate to PostgreSQL (requires PL/R)
CREATE AGGREGATE public.median(double precision) (
SFUNC=public.plr_array_accum,
STYPE=float8[],
FINALFUNC=r_median
);
CREATE OR REPLACE FUNCTION public.r_median(double precision[])
RETURNS double precision AS
$BODY$
median(arg1)
$BODY$ LANGUAGE plr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment