Re: how do I capture conflicting rows - Mailing list pgsql-admin

From Alvaro Herrera
Subject Re: how do I capture conflicting rows
Date
Msg-id 20230515111554.2a2q3hg2b4s5l7wh@alvherre.pgsql
Whole thread Raw
In response to how do I capture conflicting rows  (Nikhil Ingale <niks.bgm@gmail.com>)
List 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."



pgsql-admin by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Options for more aggressive space reclamation in vacuuming?
Next
From: Scott Ribe
Date:
Subject: Re: how do I capture conflicting rows