create the sfunc
CREATE or replace FUNCTION uuid_set_intersect(uuid[], uuid[])
RETURNS uuid[]
language plpgsql
IMMUTABLE
as $FUNCTION$
declare _r uuid[];
begin
if $1 = '{00000000-0000-0000-0000-000000000000}'::uuid[] then
_r := $2;
else
SELECT ARRAY(
SELECT UNNEST($1)
INTERSECT
SELECT UNNEST($2)
) into _r;
end if;
return _r;
end;
$FUNCTION$;
drop aggregate if exists uuid_set_intersect_agg(uuid[]);
create aggregate uuid_set_intersect_agg(uuid[])(
sfunc = uuid_set_intersect,
stype = uuid[],
INITCOND = '{00000000-0000-0000-0000-000000000000}'
);
- https://www.postgresql.org/docs/11/sql-createaggregate.html