Dump not-null constraints on inherited columns correctly
authorÁlvaro Herrera <[email protected]>
Fri, 13 Dec 2024 06:38:49 +0000 (07:38 +0100)
committerÁlvaro Herrera <[email protected]>
Fri, 13 Dec 2024 06:38:49 +0000 (07:38 +0100)
commitfd41ba93e4630921a72ed5127cd0d552a8f3f8fc
tree4606fb302c13cbf1a274a097a0ea4b3a0fc5e6d2
parenta0ff56e2d3ff1db3de727b33b2dac985ccc43ef8
Dump not-null constraints on inherited columns correctly

With not-null constraints defined in child tables for columns that are
coming from their parent tables, we were printing ALTER TABLE SET NOT
NULL commands that were missing the constraint name, so the original
constraint name was being lost, which is bogus.  Fix by instead adding
a table-constraint constraint declaration with the correct constraint
name in the CREATE TABLE instead.

Oversight in commit 14e87ffa5c54.

We could have fixed it by changing the ALTER TABLE SET NOT NULL to ALTER
TABLE ADD CONSTRAINT, but I'm not sure that's any better.  A potential
problem here might be that if sent to a non-Postgres server, the new
pg_dump output would fail because the "CONSTRAINT foo NOT NULL colname"
syntax isn't SQL-conforming.  However, Postgres' implementation of
inheritance is already non-SQL-conforming, so that'd likely fail anyway.

This problem was only noticed by Ashutosh's proposed test framework for
pg_dump, https://postgr.es/m/CAExHW5uF5V=Cjecx3_Z=7xfh4rg2Wf61PT+hfquzjBqouRzQJQ@mail.gmail.com

Author: Ashutosh Bapat <[email protected]>
Reported-by: Ashutosh Bapat <[email protected]>
Reviewed-by: Alvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/CAExHW5tbdgAKDfqjDJ-7Fk6PJtHg8D4zUF6FQ4H2Pq8zK38Nyw@mail.gmail.com
src/bin/pg_dump/pg_dump.c