Re: how do I capture conflicting rows

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Nikhil Ingale <niks(dot)bgm(at)gmail(dot)com>
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: how do I capture conflicting rows
Date: 2023-05-15 11:15:54
Message-ID: 20230515111554.2a2q3hg2b4s5l7wh@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 2023-May-15, Nikhil Ingale wrote:

> Hi All,
>
> The following query inserts the rows by ignoring the rows that has
> conflicts.
>
> INSERT INTO test (id,name,age,branch) SELECT * FROM student ON CONFLICT DO
> NOTHING;
>
> How do I capture the conflicting records to a file while non conflicting
> records are inserted to the table?

It sounds like you want a new feature:

INSERT INTO test (...) SELECT * FROM student
ON CONFLICT EXECUTE FUNCTION do_your_stuff(excluded);

Sounds like it could be useful, but somebody would have to design it
fully and implement it.

Or maybe just

INSERT INTO test (...) SELECT * FROM student
ON CONFLICT DO NOTHING RETURNING excluded.*;

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Now I have my system running, not a byte was off the shelf;
It rarely breaks and when it does I fix the code myself.
It's stable, clean and elegant, and lightning fast as well,
And it doesn't cost a nickel, so Bill Gates can go to hell."

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Scott Ribe 2023-05-15 13:17:36 Re: how do I capture conflicting rows
Previous Message Laurenz Albe 2023-05-15 07:56:16 Re: Options for more aggressive space reclamation in vacuuming?