pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it
2+ messages / 2 participants
[nested] [flat]

* BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it
@ 2026-10-20 09:14  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2026-10-20 09:14 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: 1482694023@qq.com

The following bug has been logged on the website:

Bug reference:      19777
Logged by:          N J
Email address:      1482694023@qq.com
PostgreSQL version: 18.6
Operating system:   Windows 11 x64
Description:        

Tested with PostgreSQL 18.6 on Windows 11 x64. No extensions or non-default
configuration are required.

On a fresh connection, run the setup and check:

CREATE TEMP TABLE period_parent_minimal (
    k int4range NOT NULL,
    p int4range NOT NULL,
    PRIMARY KEY (k, p WITHOUT OVERLAPS)
);

INSERT INTO period_parent_minimal
VALUES ('[1,2)'::int4range, '[0,10)'::int4range);

CREATE TEMP TABLE period_child_minimal (
    k int4range NOT NULL,
    p int4range NOT NULL,
    FOREIGN KEY (k, PERIOD p)
        REFERENCES period_parent_minimal (k, PERIOD p)
);

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:

INSERT INTO period_child_minimal
VALUES ('[1,2)'::int4range, 'empty'::int4range);

Actual result: rejected with SQLSTATE 23503 (foreign key violation).

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.








^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it
@ 2026-10-27 04:14  Takeshi Ideriha <iderihatakeshi@gmail.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Takeshi Ideriha @ 2026-10-27 04:14 UTC (permalink / raw)
  To: 1482694023@qq.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form <noreply@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






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-10-27 04:14 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 09:14 BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it PG Bug reporting form <noreply@postgresql.org>
2026-10-27 04:14 ` Takeshi Ideriha <iderihatakeshi@gmail.com>

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