Re: BUG #19698: IMPORT FOREIGN SCHEMA treats a NOT VALID NOT NULL constraint as validated - Mailing list pgsql-bugs

From Kirill Reshke
Subject Re: BUG #19698: IMPORT FOREIGN SCHEMA treats a NOT VALID NOT NULL constraint as validated
Date
Msg-id CALdSSPjL=bQoEeiaf=4nrG04-nG5rH1mEuUu5Y+-dWNTA4koPQ@mail.gmail.com
Whole thread
In response to BUG #19698: IMPORT FOREIGN SCHEMA treats a NOT VALID NOT NULL constraint as validated  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #19698: IMPORT FOREIGN SCHEMA treats a NOT VALID NOT NULL constraint as validated
List pgsql-bugs
On Fri, 18 Sept 2026 at 13:25, PG Bug reporting form
<noreply@postgresql.org> wrote:
>
> The following bug has been logged on the website:

> Description
> -----------
> When IMPORT FOREIGN SCHEMA imports a remote table having a NOT NULL
> constraint declared NOT VALID, postgres_fdw creates trusted local NOT NULL
> metadata. The remote table can still contain NULL values because its
> constraint has not been validated. With constraint_exclusion enabled,
> PostgreSQL relies on the imported metadata and incorrectly excludes a query
> that would find such a row. Queries through the imported foreign table can
> therefore silently omit existing rows.


I think this analysis is correct. Thanks.

One simple fix can be simply importing NOT NULL NOT VALID as a
nullable column, but this probably would make some people unhappy.

Another option is to actually declare the column as NOT NULL NOT
VALID. This patch is required to support NOT VALID constr during
create DDL.
NOT VALID contrs are impossible for regular relation since they are
created empty, but that's not the case for FDW. I have done this in
simple POC

PFA both patches.

-- 
Best regards,
Kirill Reshke

Attachment

pgsql-bugs by date:

Previous
From: Kirill Reshke
Date:
Subject: Re: BUG #19698: IMPORT FOREIGN SCHEMA treats a NOT VALID NOT NULL constraint as validated
Next
From: Jeff Davis
Date:
Subject: bug: Gather rescan keeps the first scan's tuple bound in workers