Improve upcasting for INT range and multi range types

From: Federico <cfederico87(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Improve upcasting for INT range and multi range types
Date: 2023-12-07 20:21:11
Message-ID: CAN19dyc8ey8_di+Lbsoh4et1d85Caaq2w4VTPcPNMYP-QVOsDg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Postgresql seems to be missing upcasting when doing INT range and
multi-range operation, for example when checking if an int4 is inside
an int8 range.
Some non working example are the following

SELECT 2::INT4 <@ '[1, 4)'::INT8RANGE
-- ERROR: operator does not exist: integer <@ int8range

SELECT 1::INT4 <@ '{[1, 4),[6,19)}'::INT8MULTIRANGE
-- ERROR: operator does not exist: integer <@ int8multirange

SELECT 1::INT2 <@ '{[1, 4),[6,19)}'::INT4MULTIRANGE
-- ERROR: operator does not exist: smallint <@ int4multirange

SELECT '[2, 3]'::INT4RANGE <@ '[1, 42)'::INT8RANGE
-- ERROR: operator does not exist: int4range <@ int8range

SELECT 2::INT8 <@ '[1, 4)'::INT4RANGE
-- ERROR: operator does not exist: bigint <@ int4range

etc.

In all these cases the smaller integer type can be upcasted to the
larger integer type.

Posted here since it doesn't seem like a bug, just a missing feature.

Thanks for reading
Federico

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2023-12-07 20:45:27 Re: CREATE FUNCTION ... SEARCH { DEFAULT | SYSTEM | SESSION }
Previous Message Robert Haas 2023-12-07 19:51:06 Re: Proposal to add page headers to SLRU pages