[postgis-users] Slow delete of duplicate rows

Andy Colson andy at squeakycode.net
Mon Mar 5 10:32:04 PST 2012


On 3/5/2012 11:15 AM, Nicolas Ribot wrote:
> Hi,
>
> Try the "NOT EXISTS" construct. I found it is order of magnitude
> faster than "NOT IN".
>
> It should be something like (test the query before using it, i'm not
> sure of it :)
>
> DELETE FROM portal.metadata
> WHERE NOT EXISTS
> (
>     SELECT MIN(idx)
>     FROM portal.metadata
>     GROUP BY "data_object.unique_id"
> );
>

ahh, no, I dont think that's right.  min() will always return a record, 
so exists will always be true.  exists() is true when count(*) > 0.

-Andy




More information about the postgis-users mailing list