Re: cataloguing NOT NULL constraints

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: cataloguing NOT NULL constraints
Date: 2023-02-28 19:15:37
Message-ID: 20230228191537.x4sepwytcclxpl3j@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

So I reworked this to use a new contype value for the NOT NULL
pg_constraint rows; I attach it here. I think it's fairly clean.

0001 is just a trivial change that seemed obvious as soon as I ran into
the problem.

0002 is the most interesting part.

Things that are curious:

- Inheritance and primary keys. If you have a table with a primary key,
and create a child of it, that child is going to have a NOT NULL in the
column that is the primary key.

- Inheritance and plain constraints. It is not allowed to remove the
NOT NULL constraint from a child; currently, NO INHERIT constraints are
not supported. I would say this is an useless feature, but perhaps not.

Since nobody liked the idea of listing the constraints in psql \d's
footer, I changed \d+ so that the "not null" column shows the name of
the constraint if there is one, or the string "(primary key)" if the
attnotnull marking for the column comes from the primary key. The new
column is going to be quite wide in some cases; if we want to hide it
further, we could add the mythical \d++ and have *that* list the
constraint name, keeping \d+ as current.

Álvaro Herrera PostgreSQL Developer —
"Los trabajadores menos efectivos son sistematicamente llevados al lugar
donde pueden hacer el menor daño posible: gerencia." (El principio Dilbert)

Attachment Content-Type Size
v3-0001-ALTER-TABLE-ADD-PRIMARY-KEY-mention-table-name-in.patch text/x-diff 991 bytes
v3-0002-Rebase-of-catalog-notnull-6-minus-psql-d-changes.patch text/x-diff 163.9 KB
v3-0003-have-psql-d-show-the-constraint-name.patch text/x-diff 245.4 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2023-02-28 19:28:30 Re: Non-superuser subscription owners
Previous Message Jacob Champion 2023-02-28 19:02:42 Re: Experiments with Postgres and SSL