Re: PostgreSQL CHECK Constraint

From: Christian Ramseyer <ramseyer(at)netnea(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: PostgreSQL CHECK Constraint
Date: 2021-10-03 14:01:57
Message-ID: 42aaef2a-6f55-0449-5a35-d6507d333af1@netnea.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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(at)dellstore ERROR: new row for relation "test_customers"
violates check constraint "check_age"

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

postgres(at)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message FOUTE K. Jaurès 2021-10-03 14:40:33 Re: PostgreSQL - Ordering Table based of Foreign Key
Previous Message Andreas Joseph Krogh 2021-10-03 09:26:05 Re: PostgreSQL - Ordering Table based of Foreign Key

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2021-10-03 18:16:32 Re: PostgreSQL CHECK Constraint
Previous Message Shaozhong SHI 2021-10-03 07:31:13 PostgreSQL CHECK Constraint