Re: How to capture error message and save to a table in PostgreSQL?

From: Steve Midgley <science(at)misuse(dot)org>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: How to capture error message and save to a table in PostgreSQL?
Date: 2021-10-08 17:09:25
Message-ID: CAJexoS+DZ49AE2hKTWr-7-1L3Zzw+OfABLLpZZq-2XJpKbBR2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Oct 8, 2021 at 2:46 AM Shaozhong SHI <shishaozhong(at)gmail(dot)com> wrote:

> Hi, All,
>
> I wish to test out to produce a table when data violates constraints when
> insert into a new table with constraint set. How to capture and save error
> message to a new table?
>
> INSERT INTO test3 ("Record Type", "Unique Reference Number", "Supplier
> Reference Number", "Post Code")
> SELECT "Record Type", "Unique Reference Number", "Supplier Reference
> Number", "Post Code" from test;
>
> ERROR: new row for relation "test3" violates check constraint "test3_Post
> Code_check"
> DETAIL: Failing row contains (L, 14986526, 1207174, null, null, null,
> null, null, null, SURREY, null, null, null, null, null, null, null, null).
> SQL state: 23514
>
>
Maybe create a trigger and trigger on error? I've never done it but it
looks like it is doable.. Does this help?

https://www.postgresql.org/docs/14/plpgsql-trigger.html
https://www.postgresql.org/docs/14/event-trigger-example.html

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Steve Midgley 2021-10-08 19:01:59 Re: A new scenario for check constraints
Previous Message Shaozhong SHI 2021-10-08 11:13:51 A new scenario for check constraints