BUG #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it

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 #19777: PERIOD foreign key rejects an empty referencing range even though the referenced period covers it
Date: 2026-10-20 09:14:48
Message-ID: 19777-e1090cf88c970b8b@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: 19777
Logged by: N J
Email address: 1482694023(at)qq(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Fujii Masao 2026-10-20 09:31:18 Re: START_REPLICATION silently truncates an overlong LSN component
Previous Message Michael Paquier 2026-10-20 07:54:30 Re: BUG #19760: CLUSTER loses a row the transaction inserted and then updated in a rolled-back subtransaction