I'm using PostGIS to process some complex land use data. I have several cases were there were exact duplicate polygons created. I'd like to delete these duplicates, and I am currently using the following self-join SQL to remove the duplicates:
delete from landusetable where objectid in
(select max(x.objectid) from landusetable x JOIN landusetable y ON
ST_Equals(x.shape, y.shape) WHERE x.objectid <> y.objectid group by x.shape);
This works fine to remove the duplicate with the higher objectid value, however it only removes the highest objectid. If there are 3 or more duplicate polygons, I need to run this statement multiple times until the delete statement affects 0 rows, then I know I've removed all of the duplicates.
So, using a PL/pgSQL function or other control structure, how can I run the statement above multiple times until I receive "DELETE 0", then quit? I looked through the documentation, but I couldn't find how to receive the number of affected rows from the previous query using PL/pgSQL.
Any assistance you could provide would be greatly appreciated!