Re: PostgreSQL CHECK Constraint

Поиск
Список
Период
Сортировка
От Shaozhong SHI
Тема Re: PostgreSQL CHECK Constraint
Дата
Msg-id CA+i5JwbQR7kYG02LuNxfsyCcGH9YkMhdYKJ3fx78LorU-CyzLA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: PostgreSQL CHECK Constraint  (Christian Ramseyer <ramseyer@netnea.com>)
Ответы Re: PostgreSQL CHECK Constraint  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Re: PostgreSQL CHECK Constraint  (Christian Ramseyer <ramseyer@netnea.com>)
Список pgsql-general
Hi, Christian,
That is interesting.  Can errors be captured and saved as data with scripting?
Regards,
David

On Sunday, 3 October 2021, Christian Ramseyer <ramseyer@netnea.com> wrote:


On 03.10.21 09:31, Shaozhong SHI wrote:
>
> Has anyone got experience with data quality checking, validation and
> reporting within PostgreSQL?
>
> How best to use PostgreSQL CHECK Constraint for data quality checking,
> validation and reporting?  
>
> Can we report on errors in a detailed and specific way?  For instance,
> can we produce report on specific issues of erroneous cells in which row
> and etc.?
>

Yes that's all possible. Given a constraint like

alter table test_customers
   add constraint check_age check (age >= 18);


The reported error looks like this:

postgres@dellstore ERROR:  new row for relation "test_customers"
violates check constraint "check_age"

postgres@dellstore DETAIL:  Failing row contains (1, Jimmy, Schmoe, 15).

postgres@dellstore STATEMENT:  insert into test_customers (firstname,
lastname, age) values ( 'Jimmy', 'Schmoe', 15);

This errors appears in the serverlog which has many format and
forwarding options, you can read about them here:

https://www.postgresql.org/docs/current/runtime-config-logging.html

Cheers
Christian

--
Christian Ramseyer, netnea ag
Network Management. Security. OpenSource.
https://www.netnea.com

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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: pg_dump save command in output
Следующее
От: Karsten Hilbert
Дата:
Сообщение: Re: PostgreSQL CHECK Constraint