Re: Check for duplicates before inserting new rows

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Check for duplicates before inserting new rows
Date: 2020-09-04 14:40:00
Message-ID: alpine.LNX.2.20.2009040736090.7473@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 4 Sep 2020, George Woodring wrote:

> I would suggest creating a temp table based on the original table and
> loading the data into it first. You can then purge the duplicates.

George,

I hadn't thought of this. Using a duplicate table without a PK would work
well if there's only one attribute that needs checking.

In my case there are two tables involved: locations and measurements. So, I
can create a temporary table from the new data which holds only the
locations. I can then isolate the new location rows that do not already
exist in that table, then insert the new data to eliminate the duplicated
measurements.

Thanks,

Rich

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2020-09-04 14:41:21 Re: Bitmap scan seem like such a strange choice when "limit 1"
Previous Message George Woodring 2020-09-04 13:27:14 Re: Check for duplicates before inserting new rows