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

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

  1. pg_dump: Preserve NO INHERIT on NOT NULL on inheritance children

  2. Dump not-null constraints on inherited columns correctly