BUG #19753: PERIOD foreign key rejects an empty referencing range although the coverage test returns true

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: 1482694023(at)qq(dot)com
Subject: BUG #19753: PERIOD foreign key rejects an empty referencing range although the coverage test returns true
Date: 2026-10-10 15:10:24
Message-ID: 19753-e0e5fc5bef24f5ab@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19753
Logged by: N J
Email address: 1482694023(at)qq(dot)com
PostgreSQL version: 18.6
Operating system: Windows 11 64-bit
Description:

PostgreSQL version: 18.6
Client: pgAdmin 4
Operating system: Windows 11 64-bit

Steps to reproduce:

CREATE EXTENSION IF NOT EXISTS btree_gist;

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

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

CREATE TEMP TABLE child_period (
k integer NOT NULL,
p int4range NOT NULL,
FOREIGN KEY (k, PERIOD p)
REFERENCES parent_period (k, PERIOD p)
);

SELECT range_agg(p) @> 'empty'::int4range AS covered
FROM parent_period
WHERE k = 1;

The SELECT returns true.

Then run:

INSERT INTO child_period VALUES (1, 'empty'::int4range);

Actual result:
The INSERT fails with SQLSTATE 23503 (foreign_key_violation):
Key (k, p)=(1, empty) is not present in table "parent_period".

Expected result:
I expected the INSERT to succeed because the referencing period is empty and
the coverage query returns true. This expectation follows the documented
PERIOD foreign-key coverage rule and the set-containment behavior of empty
ranges.

The behavior appears inconsistent between the coverage query and PERIOD
foreign-key enforcement. I have reproduced it on this installation, but have
not established the underlying cause.

Browse pgsql-bugs by date

  From Date Subject
Next Message Chinmay Kanchi 2026-10-11 02:04:42 GIN (JSONPath) checks equality only on the first node of each operand
Previous Message Zsolt Parragi 2026-10-10 11:51:29 Re: PG18: use-after-free in exec partition pruning after an EPQ recheck in LockRows