create or replace function toset(l) as array_sort(list_distinct(l)); create or replace function array_intersection(a,b) as array_filter(a, x -> array_contains(b, x)); create or replace function set_union(a,b) as toset(toset(a) || toset(b))); create or replace function set_intersection(a,b) as array_intersection(toset(a),toset(b));