pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Takeshi Ideriha <iderihatakeshi@gmail.com>
To: 1482694023@qq.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form <noreply@postgresql.org>
Subject: Re: BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it
Date: Tue, 27 Oct 2026 13:14:31 +0900
Message-ID: <637f15f1-847e-4587-8aa1-7148f5e99699@gmail.com> (raw)
In-Reply-To: <19777-e1090cf88c970b8b@postgresql.org>
References: <19777-e1090cf88c970b8b@postgresql.org>

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






view thread (2+ messages)

Message-ID: <637f15f1-847e-4587-8aa1-7148f5e99699@gmail.com>
Permalink:  ../637f15f1-847e-4587-8aa1-7148f5e99699@gmail.com/
Also on:    postgresql.org/message-id/637f15f1-847e-4587-8aa1-7148f5e99699@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: iderihatakeshi@gmail.com, noreply@postgresql.org
  Subject: Re: BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it
  In-Reply-To: <637f15f1-847e-4587-8aa1-7148f5e99699@gmail.com>
  References: <19777-e1090cf88c970b8b@postgresql.org> <637f15f1-847e-4587-8aa1-7148f5e99699@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox