pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: how do I capture conflicting rows
Date: Mon, 15 May 2023 01:09:24 -0500
Message-ID: <34308ba9-6033-6e57-f44e-500b2ca9cad5@gmail.com> (raw)
In-Reply-To: <CALXkTpx3iLuGRx1_4N6GJ85ptoW4n4XSdh3ChJLE-hrFGC982g@mail.gmail.com>
References: <CALXkTpx3iLuGRx1_4N6GJ85ptoW4n4XSdh3ChJLE-hrFGC982g@mail.gmail.com>

On 5/15/23 00:32, 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?

On conflict insert the PK into a separate table, along with a timestamp 
column populated by clock_timestamp().  (That way you can export and delete 
sets of records while it's being written to.

-- 
Born in Arizona, moved to Babylonia.





view thread (8+ messages)  latest in thread

Message-ID: <34308ba9-6033-6e57-f44e-500b2ca9cad5@gmail.com>
Permalink:  ../34308ba9-6033-6e57-f44e-500b2ca9cad5@gmail.com/
Also on:    postgresql.org/message-id/34308ba9-6033-6e57-f44e-500b2ca9cad5@gmail.com

 · 

reply

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: ronljohnsonjr@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: how do I capture conflicting rows
  In-Reply-To: <34308ba9-6033-6e57-f44e-500b2ca9cad5@gmail.com>

* 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