Re: COPY from .csv File and Remove Duplicates - Mailing list pgsql-general

From David Johnston
Subject Re: COPY from .csv File and Remove Duplicates
Date
Msg-id 6CA55C4C-D5C4-43DE-9B35-99C2D6622E4D@yahoo.com
Whole thread Raw
In response to Re: COPY from .csv File and Remove Duplicates  (Rich Shepard <rshepard@appl-ecosys.com>)
Responses Re: COPY from .csv File and Remove Duplicates
Re: COPY from .csv File and Remove Duplicates
List pgsql-general
>  A pointer to the appropriate syntax for retrieving the entire row when
> count(loc_name, sample_date, param) > 1 would be much appreciated.
>
> Rich
>

Select *
From table
Natural Inner join (
SELECT loc_name, sample_date, param, Count(*) as duplicate_count
FROM table
Group by loc_name, sample_date, param
) grouped
Where duplicate_count > 1
;

You first group and count on the candidate key and then effectively self-joint that result back onto the original
table. natural join is short-hand for cases where the two joining table use the same name for semantically identical
field. Much easier than saying "t1.field1 = t2.field1 AND t1.field2 = t2.field2 AND etc..." 

David J.

pgsql-general by date:

Previous
From: Rich Shepard
Date:
Subject: Re: COPY from .csv File and Remove Duplicates
Next
From: George MacKerron
Date:
Subject: Functions returning setof record -- can I use a table type as my return type hint?