Re: Check for duplicates before inserting new rows

2020-09-04 Thread Rich Shepard
On Fri, 4 Sep 2020, Chris Sterritt wrote: Assuming some simple table structures (I've not included PK or FK definitions for simplicity): Chris, Thanks very much. Stay well, Rich

Re: Check for duplicates before inserting new rows

2020-09-04 Thread Chris Sterritt
On 04/09/2020 14:21, Rich Shepard wrote: 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 statio

Re: Check for duplicates before inserting new rows

2020-09-04 Thread Chris Sterritt
On 04/09/2020 15:46, Rich Shepard wrote: 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 h

Re: Check for duplicates before inserting new rows

2020-09-04 Thread Rich Shepard
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-i

Re: Check for duplicates before inserting new rows

2020-09-04 Thread Rich Shepard
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 attrib

Re: Check for duplicates before inserting new rows

2020-09-04 Thread George Woodring
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 Woodring iGLASS Networks www.iglass.net On Fri, Sep 4, 2020 at 9:21 AM Rich Shepard wrote: > This is a new issue for me: I've received data from a di

Check for duplicates before inserting new rows

2020-09-04 Thread Rich Shepard
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 m