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 1kEBea-0006E8-QS for pgsql-general@arkaria.postgresql.org; Fri, 04 Sep 2020 13:21:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kEBeY-000598-9n for pgsql-general@arkaria.postgresql.org; Fri, 04 Sep 2020 13:21:18 +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 1kEBeY-000591-1w for pgsql-general@lists.postgresql.org; Fri, 04 Sep 2020 13:21:18 +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 1kEBeR-0003UN-Ml for pgsql-general@lists.postgresql.org; Fri, 04 Sep 2020 13:21:17 +0000 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 0C15D264EFC for ; Fri, 4 Sep 2020 06:21:10 -0700 (PDT) Date: Fri, 4 Sep 2020 06:21:10 -0700 (PDT) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Check for duplicates before inserting new rows Message-ID: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a new issue for me: I've received data from a different source and need to add non-duplicates to two tables in the database. Each row in the new data has a station ID and associated measurements. The existing database includes a table for station information and another for measurements made there. I want to learn which stations and which measurements in the new data set are not included in the existing tables. And, I don't want to try inserting the new data and have postgres tell me when it's found duplicates, especially since there are two tables involved. My research into how to do this has not found a solution so I ask for pointers to resources that will teach me how to add these new data to both tables. Regards, Rich