From: | Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com> |
---|---|
To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
Cc: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: cataloguing NOT NULL constraints |
Date: | 2022-09-19 14:10:17 |
Message-ID: | CAEze2WhmQTBExKBEOeQ6SObXB_Nh3CgmomxkyAXi7odkz9uv_w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, 19 Sept 2022 at 15:32, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
> On Wed, Aug 17, 2022 at 2:12 PM Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Bharath Rupireddy | 2022-09-19 14:19:21 | Re: Switching XLog source from archive to streaming when primary available |
Previous Message | Tom Lane | 2022-09-19 14:08:52 | Re: cataloguing NOT NULL constraints |