postgres.git / summary / log / commit / refs
commit c3c8b63d76be16d7fbd9d309e8b640c43554c453
Author: Álvaro Herrera <alvherre@kurilemu.de>
Date: Thu Feb 26 10:50:26 2026 +0000
First released in: 19.0, 18.4
pg_dump: Preserve NO INHERIT on NOT NULL on inheritance children
When the constraint is printed without the column, we were not printing
the NO INHERIT flag.
Author: Jian He <jian.universality@gmail.com>
Backpatch-through: 18
Discussion: https://postgr.es/m/CACJufxEDEOO09G+OQFr=HmFr9ZDLZbRoV7+pj58h3_WeJ_K5UQ@mail.gmail.com
src/bin/pg_dump/pg_dump.c | 3 +++
src/bin/pg_dump/t/002_pg_dump.pl | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 583afc67d3f..077da79ead8 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -17230,6 +17230,9 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
appendPQExpBuffer(q, "CONSTRAINT %s NOT NULL %s",
tbinfo->notnull_constrs[j],
fmtId(tbinfo->attnames[j]));
+
+ if (tbinfo->notnull_noinh[j])
+ appendPQExpBufferStr(q, " NO INHERIT");
}
}
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index eba7d5775b5..9512e2d89e5 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -1336,6 +1336,43 @@ my %tests = (
},
},
+ 'CONSTRAINT NOT NULL / NO INHERIT' => {
+ create_sql => 'CREATE TABLE dump_test.test_table_nonn (
+ col1 int NOT NULL NO INHERIT,
+ col2 int);
+ CREATE TABLE dump_test.test_table_nonn_chld1 (
+ CONSTRAINT nn NOT NULL col2 NO INHERIT)
+ INHERITS (dump_test.test_table_nonn); ',
+ regexp => qr/^
+ \QCREATE TABLE dump_test.test_table_nonn (\E \n^\s+
+ \Qcol1 integer NOT NULL NO INHERIT\E
+ /xm,
+ like => {
+ %full_runs, %dump_test_schema_runs,
+ section_pre_data => 1,
+ binary_upgrade => 1,
+ },
+ unlike => {
+ exclude_dump_test_schema => 1,
+ only_dump_measurement => 1,
+ },
+ },
+
+ 'CONSTRAINT NOT NULL / NO INHERIT (child1)' => {
+ regexp => qr/^
+ \QCREATE TABLE dump_test.test_table_nonn_chld1 (\E \n^\s+
+ \QCONSTRAINT nn NOT NULL col2 NO INHERIT\E
+ /xm,
+ like => {
+ %full_runs, %dump_test_schema_runs, section_pre_data => 1,
+ },
+ unlike => {
+ exclude_dump_test_schema => 1,
+ only_dump_measurement => 1,
+ binary_upgrade => 1,
+ },
+ },
+
'CONSTRAINT PRIMARY KEY / WITHOUT OVERLAPS' => {
create_sql => 'CREATE TABLE dump_test.test_table_tpk (
col1 int4range,
[parent: 95e0fac1ee76]