persevere NO INHERIT when Dump not-null constraints on inherited columns
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-02-25T14:38:20Z
Lists: pgsql-hackers
Attachments
- pg_dump_no_inherit_inherit_col.diff (text/x-patch) patch
Hi.
Related: https://git.postgresql.org/cgit/postgresql.git/commit/?id=fd41ba93e4630921a72ed5127cd0d552a8f3f8fc
create table p1(f1 int);
create table p1_c1() inherits(p1);
alter table p1_c1 add constraint p1c1_a_nn not null f1 no inherit;
pg_dump --table-and-children=p1* --clean --if-exists --no-data
output:
---------------<<<<<<
DROP TABLE IF EXISTS public.p1_c1;
DROP TABLE IF EXISTS public.p1;
CREATE TABLE public.p1 (
f1 integer
);
CREATE TABLE public.p1_c1 (
CONSTRAINT p1c1_a_nn NOT NULL f1
)
INHERITS (public.p1);
---------------<<<<<<
for p1_c1, it should be
CREATE TABLE public.p1_c1 (
CONSTRAINT p1c1_a_nn NOT NULL f1 NO INHERIT
)
INHERITS (public.p1);
add
```
if (tbinfo->notnull_noinh[j])
appendPQExpBufferStr(q, " NO INHERIT");
```
at the end of IF loop
```
if (!shouldPrintColumn(dopt, tbinfo, j) &&
!tbinfo->attisdropped[j] &&
tbinfo->notnull_constrs[j] != NULL &&
tbinfo->notnull_islocal[j])
{
}
```
will fix this problem.
--
jian
https://www.enterprisedb.com/
Commits
-
pg_dump: Preserve NO INHERIT on NOT NULL on inheritance children
- d0833fdae7eb 19 (unreleased) landed
- c3c8b63d76be 18.4 landed
-
Dump not-null constraints on inherited columns correctly
- fd41ba93e463 18.0 cited