Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kECsn-0001FM-KY for pgsql-general@arkaria.postgresql.org; Fri, 04 Sep 2020 14:40:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kECsm-0007aR-Eb for pgsql-general@arkaria.postgresql.org; Fri, 04 Sep 2020 14:40:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kECsm-0007aK-74 for pgsql-general@lists.postgresql.org; Fri, 04 Sep 2020 14:40:04 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kECsk-0004DT-4j for pgsql-general@lists.postgresql.org; Fri, 04 Sep 2020 14:40:03 +0000 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id F31C0264EFC for ; Fri, 4 Sep 2020 07:40:00 -0700 (PDT) Date: Fri, 4 Sep 2020 07:40:00 -0700 (PDT) From: Rich Shepard To: PostgreSQL General Subject: Re: Check for duplicates before inserting new rows In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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