pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rich Shepard <rshepard@appl-ecosys.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Check for duplicates before inserting new rows
Date: Fri, 4 Sep 2020 07:46:03 -0700 (PDT)
Message-ID: <alpine.LNX.2.20.2009040745360.7473@salmo.appl-ecosys.com> (raw)

On Fri, 4 Sep 2020, Olivier Gautherot wrote:

> First of all, what version of PostgreSQL are you using?

Olivier,

12.2.

> One way would be to add a UNIQUE constraint and perform for each row of the
> source table a INSERT ... ON CONFLICT DO NOTHING (see
> https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT)
> 
> If it is a 2-way merge, I would encapsulate the process in a function
> (which will create a transaction to protect your process) and add a column
> to trace the rows that have been merged. For this purpose, you can use the
> ON CONFLICT DO UPDATE ...

Lots for me to ponder.

The new data has attributes stored in two database tables: location and
measurements. I'll need to think about how both could be handled in a single
function. For example, the new data contains a row with a location not
already in the existing location table. That location needs to be added to
the location table and its associated measurement attributes then added to
the existing measurements table.

Thanks for the suggestion,

Rich





view thread (7+ messages)  latest in thread

Message-ID: <alpine.LNX.2.20.2009040745360.7473@salmo.appl-ecosys.com>
Permalink:  ../alpine.LNX.2.20.2009040745360.7473@salmo.appl-ecosys.com/
Also on:    postgresql.org/message-id/alpine.LNX.2.20.2009040745360.7473@salmo.appl-ecosys.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rshepard@appl-ecosys.com
  Subject: Re: Check for duplicates before inserting new rows
  In-Reply-To: <alpine.LNX.2.20.2009040745360.7473@salmo.appl-ecosys.com>
  References: <alpine.LNX.2.20.2009040745360.7473@salmo.appl-ecosys.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