Re: cataloguing NOT NULL constraints

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: cataloguing NOT NULL constraints
Date: 2022-08-17 20:09:22
Message-ID: CAB-JLwYu3+M+CK3HTbBHMip2PDEPGP4NF52Yf_tiHH5d1KKOcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> I started this time around from the newest of my patches in those
> threads, but the implementation has changed considerably from what's
> there.
>

I don´t know exactly what will be the scope of this process you're working
on, but there is a gap on foreign key constraint too.
It is possible to have wrong values on a FK constraint if you disable
checking of it with session_replication_role or disable trigger all
I know you can create that constraint with "not valid" and it'll be checked
when turned on. But if I just forgot that ...
So would be good to have validate constraints which checks, even if it's
already valid

drop table if exists tb_pk cascade;create table tb_pk(key integer not null
primary key);
drop table if exists tb_fk cascade;create table tb_fk(fk_key integer);
alter table tb_fk add constraint fk_pk foreign key (fk_key) references
tb_pk (key);
insert into tb_pk values(1);
alter table tb_fk disable trigger all; --can be with
session_replication_role too.
insert into tb_fk values(5); --wrong values on that table

Then, you could check

alter table tb_fk validate constraint fk_pk
or
alter table tb_fk validate all constraints

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-08-17 20:17:36 Re: Making Vars outer-join aware
Previous Message Andres Freund 2022-08-17 20:08:56 Re: static libpq (and other libraries) overwritten on aix