similar to (int[] || int4) and (int4 || int[]) should we expect ('{1,2}'::int4hashset || 3) == (3 || '{1,2}'::int4hashset) == (select hashset_add('{1,2}'::int4hashset,3)); *?*
The following is the general idea on how to make it work by looking at similar code.... CREATE OPERATOR || ( leftarg = int4hashset, rightarg = int4, function = int4hashset_add, commutator = || ); CREATE OR REPLACE FUNCTION int4_add_int4hashset(int4, int4hashset) RETURNS int4hashset LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT COST 1 RETURN $2 || $1; CREATE OPERATOR || ( leftarg = int4, rightarg = int4hashset, function = int4_add_int4hashset, commutator = || ); while creating an operator. I am not sure how to specify NEGATOR,RESTRICT,JOIN clause. ----------------------------------------------------------------------------------------------------------------------------- also. I think the following query should return one row only? but now it doesn't. select hashset_cmp('{1,2}','{2,1}') union select hashset_cmp('{1,2}','{1,2,1}') union select hashset_cmp('{1,2}','{1,2}'); ---------------------------------------------------------------------------------------------------------------------- similar to elem_contained_by_range, range_contains_elem. we should already consider the operator *<@* and @*>? * CREATE OR REPLACE FUNCTION elem_contained_by_hashset(int4, int4hashset) RETURNS bool LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT COST 1 RETURN hashset_contains ($2,$1); Is the integer contained in the int4hashset? integer <@ int4hashset → boolean 1 <@ int4hashset'{1,7}' → t CREATE OPERATOR <@ ( leftarg = integer, rightarg = int4hashset, function = elem_contained_by_hashset ); int4hashset @> integer → boolean Does the int4hashset contain the element? int4hashset'{1,7}' @> 1 → t CREATE OPERATOR @> ( leftarg = int4hashset, rightarg = integer, function = hashset_contains ); -------------------