I have a set of point dataset in postgis with xcoordinate and ycordinate. There are few points which overlapped with each other as they are having same xcoordinate and ycoordniate. How to find the overlapped points using query in postgresql?
1 Answers
4
votes
There are at least two ways to find duplicate records using aggregate functions. Assume a table my_table
with geometry column geom
and primary key gid
:
First, using a HAVING
statement, and collecting the primary keys with array_agg
:
SELECT array_agg(gid), count(*)
FROM my_table
GROUP BY geom
HAVING count(gid) > 1;
Second, using a WINDOW
to count the partitions.
WITH data AS (
SELECT gid, count(*) OVER (PARTITION BY geom)
FROM my_table
)
SELECT * FROM data WHERE count > 1;