Re: cataloguing NOT NULL constraints

Поиск
Список
Период
Сортировка
От Isaac Morland
Тема Re: cataloguing NOT NULL constraints
Дата
Msg-id CAMsGm5dvPzXiq9=W1kbKcQGQxMHG3JJy1XZD4Dh8hOM7RD_18w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: cataloguing NOT NULL constraints  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: cataloguing NOT NULL constraints  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: cataloguing NOT NULL constraints  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Список pgsql-hackers
On Mon, 19 Sept 2022 at 09:32, Robert Haas <robertmhaas@gmail.com> wrote:
On Wed, Aug 17, 2022 at 2:12 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
> If you say CREATE TABLE (a int NOT NULL), you'll get a CHECK constraint
> printed by psql: (this is a bit more noisy that previously and it
> changes a lot of regression tests output).
>
> 55489 16devel 1776237=# create table tab (a int not null);
> CREATE TABLE
> 55489 16devel 1776237=# \d tab
>                     Tabla «public.tab»
>  Columna │  Tipo   │ Ordenamiento │ Nulable  │ Por omisión
> ─────────┼─────────┼──────────────┼──────────┼─────────────
>  a       │ integer │              │ not null │
> Restricciones CHECK:
>     "tab_a_not_null" CHECK (a IS NOT NULL)

In a table with many columns, most of which are NOT NULL, this is
going to produce a ton of clutter. I don't like that.

I'm not sure what a good alternative would be, though.

I thought I saw some discussion about the SQL standard saying that there is a difference between putting NOT NULL in a column definition, and CHECK (column_name NOT NULL). So if we're going to take this seriously, I think that means there needs to be a field in pg_constraint which identifies whether a constraint is a "real" one created explicitly as a constraint, or if it is just one created because a field is marked NOT NULL.

If this is correct, the answer is easy: don't show constraints that are there only because of a NOT NULL in the \d or \d+ listings. I certainly don't want to see that clutter and I'm having trouble seeing why anybody else would want to see it either; the information is already there in the "Nullable" column of the field listing.

The error message for a duplicate constraint name when creating a constraint needs however to be very clear that the conflict is with a NOT NULL constraint and which one, since I'm proposing leaving those ones off the visible listing, and it would be very bad for somebody to get "duplicate name" and then be unable to see the conflicting entry.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: cataloguing NOT NULL constraints
Следующее
От: Bharath Rupireddy
Дата:
Сообщение: Add LSN along with offset to error messages reported for WAL file read/write/validate header failures