clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2805438 fiddles created (40835 in the last week).

create or replace function f_sum_distinct (numeric[], numeric) returns numeric[] language sql as $$ select $1||$2; $$;
 hidden batch(es)


create or replace function f_sum_distinct_final (numeric[]) returns numeric language sql as $$ select sum(distinct v) from (select distinct unnest($1) v) z; $$;
 hidden batch(es)


create aggregate sum_distinct(numeric) ( sfunc = f_sum_distinct ,stype = numeric[] ,finalfunc = f_sum_distinct_final );
 hidden batch(es)


select sum(distinct g) "SUM(DISTINCT)", clock_timestamp()-statement_timestamp() from generate_series(1, 10000) g;
SUM(DISTINCT) ?column?
50005000 00:00:00.00305
 hidden batch(es)


select sum_distinct(g) "SUM_DISTINCT", clock_timestamp()-statement_timestamp() from generate_series(1, 10000) g;
SUM_DISTINCT ?column?
50005000 00:00:01.336863
 hidden batch(es)