Re: cataloguing NOT NULL constraints

Поиск
Список
Период
Сортировка
От Matthias van de Meent
Тема Re: cataloguing NOT NULL constraints
Дата
Msg-id CAEze2WhmQTBExKBEOeQ6SObXB_Nh3CgmomxkyAXi7odkz9uv_w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: cataloguing NOT NULL constraints  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: cataloguing NOT NULL constraints  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Список pgsql-hackers
On Mon, 19 Sept 2022 at 15: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'm not sure on the 'good' part of this alternative, but we could go
with a single row-based IS NOT NULL to reduce such clutter, utilizing
the `ROW() IS NOT NULL` requirement of a row only matching IS NOT NULL
when all attributes are also IS NOT NULL:

    Check constraints:
        "tab_notnull_check" CHECK (ROW(a, b, c, d, e) IS NOT NULL)

instead of:

    Check constraints:
        "tab_a_not_null" CHECK (a IS NOT NULL)
        "tab_b_not_null" CHECK (b IS NOT NULL)
        "tab_c_not_null" CHECK (c IS NOT NULL)
        "tab_d_not_null" CHECK (d IS NOT NULL)
        "tab_e_not_null" CHECK (e IS NOT NULL)

But the performance of repeated row-casting would probably not be as
good as our current NULL checks if we'd use the current row
infrastructure, and constraint failure reports wouldn't be as helpful
as the current attribute NOT NULL failures.

Kind regards,

Matthias van de Meent



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: cataloguing NOT NULL constraints
Следующее
От: Bharath Rupireddy
Дата:
Сообщение: Re: Switching XLog source from archive to streaming when primary available