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."