| From: | Takeshi Ideriha <iderihatakeshi(at)gmail(dot)com> |
|---|---|
| To: | 1482694023(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, PG Bug reporting form <noreply(at)postgresql(dot)org> |
| Subject: | Re: BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it |
| Date: | 2026-10-27 04:14:31 |
| Message-ID: | 637f15f1-847e-4587-8aa1-7148f5e99699@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi,
On 2026/10/20 18:14, PG Bug reporting form wrote:
>
>
> Expected result: the insert should succeed if an empty referencing period is
> considered covered by the referenced period, consistent with range
> containment and the documented PERIOD foreign-key coverage rule. Please
> confirm whether empty referencing periods are intended to satisfy PERIOD
> foreign keys.
In my opinion, this result is expected because empty is treated
differently by range type and by WITHOUT OVERLAPS constraint.
> SELECT range_agg(p) @> 'empty'::int4range AS parent_covers_empty
> FROM period_parent_minimal
> WHERE k = '[1,2)'::int4range;
>
> The SELECT returns true. Then run:
This is considered to be the same as "select '[0,10)'::int4range @>
'empty';", which returns true since 'empty' range is contained in every
range [1].
[1] https://www.postgresql.org/docs/18/functions-range.html
--
Every range contains the empty range.
--
> INSERT INTO period_child_minimal
> VALUES ('[1,2)'::int4range, 'empty'::int4range);
>
> Actual result: rejected with SQLSTATE 23503 (foreign key violation).
However, the INSERT fails. The point is a WITHOUT OVERLAPS column does
not permit empty range [2]. The referenced table does not permit empty
range so referencing table also cannot accept it.
[2] https://www.postgresql.org/docs/18/sql-createtable.html
--
The `WITHOUT OVERLAPS` column must have a range or multirange type.
Empty ranges/multiranges are not permitted.
--
Regards,
Takeshi Ideriha
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | David Rowley | 2026-10-27 04:12:19 | Re: BUG #19783: Sorted GROUPING SETS return a grouping column's value in a set that leaves it out |