Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: jian he <jian.universality@gmail.com>
Cc: Rushabh Lathia <rushabh.lathia@gmail.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2025-04-24T19:36:49Z
Lists: pgsql-hackers
Attachments
On 2025-Apr-09, jian he wrote: > hi. > > attached patch is for address pg_dump inconsistency > when parent is "not null not valid" while child is "not null". Here's my take on this patch. We don't really need the notnull_parent_invalid flag; in flagInhAttrs we can just set "islocal" to convince getTableAttrs to print the constraint. This also fixes the bug that in getTableAttrs() you handled the case where shouldPrintColumn() is true and not the other one. I also added test cases to pg_dump/t/002_pg_dump.pl to verify that the output was correct in those cases. In constraints.sql I added a couple of tables to ensure that the pg_upgrade handling (the pg_dump --binary-upgrade mode) is tested as well. Looking at the surrounding code in flagInhAttrs I noticed that we're mishandling this case: create table parent1 (a int); create table parent2 (a int); create table child () inherits (parent1, parent2); alter table parent1 add not null a; alter table parent2 add not null a not valid; We print the constraint for table child for no apparent reason. Patch 0002 is a part of your proposed patch that I don't think we need, but I'm open to hearing arguments about why we do, preferrably with some test cases. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Hay que recordar que la existencia en el cosmos, y particularmente la elaboración de civilizaciones dentro de él no son, por desgracia, nada idílicas" (Ijon Tichy)
Commits
-
Allow NOT NULL constraints to be added as NOT VALID
- a379061a22a8 18.0 landed
-
Add missing deparsing of [NO] IDENT to XMLSERIALIZE()
- 984410b92326 18.0 cited
-
backend launchers void * arguments for binary data
- 7202d72787d3 18.0 cited
-
Add pg_constraint rows for not-null constraints
- 14e87ffa5c54 18.0 cited
-
Create the infrastructure for planner support functions.
- 1fb57af92069 12.0 cited
-
Add prokind column, replacing proisagg and proiswindow
- fd1a421fe661 11.0 cited