Re: pg_upgrade failed with error - ERROR: column "a" in child table must be marked NOT NULL
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: tushar <tushar.ahuja@enterprisedb.com>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2017-07-26T14:02:55Z
Lists: pgsql-hackers
Michael Paquier <michael.paquier@gmail.com> writes: > The documentation says the following: > https://www.postgresql.org/docs/9.3/static/ddl-inherit.html > All check constraints and not-null constraints on a parent table are > automatically inherited by its children. Other types of constraints > (unique, primary key, and foreign key constraints) are not inherited. > When adding a primary key, the system does first SET NOT NULL on each > column under cover, but this does not get spread to the child tables > as this is a PRIMARY KEY. The question is, do we want to spread the > NOT NULL constraint created by the PRIMARY KEY command to the child > tables, or not? Yeah, I think we really ought to for consistency. Quite aside from pg_dump hazards, this allows situations where selecting from an apparently not-null column can produce nulls (coming from unconstrained child tables). That's exactly what the automatic inheritance rules are intended to prevent. If we had a way to mark NOT NULL constraints as not-inherited, it'd be legitimate for ADD PRIMARY KEY to paste on one of those instead of a regular one ... but we lack that feature, so it's moot. Not sure what's involved there code-wise, though, nor whether we'd want to back-patch. regards, tom lane
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix new pg_upgrade query not to rely on regnamespace
- f943e2339f6c 16.10 landed
- bd48455d88a8 15.14 landed
- bcb8d47cdd5e 17.6 landed
- 94dc2b37baee 14.19 landed
- 708469281ea8 13.22 landed
- 1e007722fa86 18.0 landed
- 144ad723a448 19 (unreleased) landed
-
pg_upgrade: check for inconsistencies in not-null constraints w/inheritance
- f63e408e894c 16.10 landed
- f295494d338c 19 (unreleased) landed
- ea3386cc784a 14.19 landed
- b8b2e60527c6 17.6 landed
- b0f0e2221f42 13.22 landed
- 0f49586850a9 15.14 landed
- 07da2985d6bf 18.0 landed
-
Apply ALTER ... SET NOT NULL recursively in ALTER ... ADD PRIMARY KEY.
- c30f1770a93d 10.0 landed