From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Nikhil Ingale <niks.bgm@gmail.com>
Cc: pgsql-admin@lists.postgresql.org
Subject: Re: how do I capture conflicting rows
Date: Mon, 15 May 2023 13:15:54 +0200
Message-ID: <20230515111554.2a2q3hg2b4s5l7wh@alvherre.pgsql> (raw)
In-Reply-To: <CALXkTpx3iLuGRx1_4N6GJ85ptoW4n4XSdh3ChJLE-hrFGC982g@mail.gmail.com>
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."
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: alvherre@alvh.no-ip.org, niks.bgm@gmail.com, pgsql-admin@lists.postgresql.org
Subject: Re: how do I capture conflicting rows
In-Reply-To: <20230515111554.2a2q3hg2b4s5l7wh@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox