'some of range_composite_type operator only check the elements of composite type

db fiddle

create type mytype as (t1 int, t2 date);
create type mytyperange as range(subtype = mytype);

seems now, operators(@>,<@, &&), compare based on the first element of the composite type. for example:

--left contain the right
select mytyperange (
    (1,'2022-01-01')::mytype,
    (8, '2022-01-31')::mytype, '[]') @> (2, '2020-01-19')::mytype;

--does the range overlaps, that is, have any common element.
select
    mytyperange ((2,'2020-12-30')::mytype,
                (2, '2020-12-31')::mytype)
    &&
    mytyperange(
    (1,'2022-01-01')::mytype,
    (8, '2022-01-31')::mytype) ;

return false, because first elements(2) in range(1,8) even though the second does not meet requirement. However << operator make sense.

select
    mytyperange (null, (-1, '2022-01-19')::mytype) <<
    mytyperange(
    (1,'2022-01-01')::mytype,
    (8, '2022-01-31')::mytype, '[]') ;

Is possible to make use range composite type to represent that the first elements in [1,8] the second element in ['2022-01-01',2022-01-31']. that means the first code example should return false.
another question: adjacent operator of composite type range how to validate it.


a better way to explain is: is possible to make mytyperange be equivalent as the following query:

select a, b::date
from generate_series(1,8) a,
generate_series('2022-01-01'::timestamp,
    '2022-01-31'::timestamp, interval '1 day') b;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source