There is no single operator to check for both (either contained or no overlap).
Not in Postgres 13, not in any standard Postgres distribution.
But you can easily create your own operator. I chose the operator name <@!&&
to be explicit and because it won't collide with any existing operator. Pick what you like, maybe something shorter since you are aiming for short code.
CREATE FUNCTION f_array_contained_or_no_overlap(anyarray, anyarray)
RETURNS boolean
LANGUAGE sql IMMUTABLE AS
'SELECT $1 <@ $2 OR NOT $1 && $2';
CREATE OPERATOR <@!&& (
FUNCTION = f_array_contained_or_no_overlap
, LEFTARG = anyarray
, RIGHTARG = anyarray
);
Then you can:
SELECT ARRAY[1,2] <@!&& ARRAY[1,2,7] AS contained -- true
, ARRAY[1,2] <@!&& ARRAY[4,5,6] AS no_overlap -- true
, ARRAY[1,2] <@!&& ARRAY[4,2,6] AS part_overlap; -- false
contained |
no_overlap |
part_overlap |
t |
t |
f |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…