I have a table of points, and I set some time ago a simple unique constraint as such :
ALTER TABLE points ADD CONSTRAINT points_geom_key UNIQUE (geom);
It generally worked fine, until now that I face a weird behaviour. I tried to directly copy/paste some points through QGIS with the copy/paste of entities, as I am generally doing, but got an error saying the constraint is not being respected. Long story short : I have two points that are nowher near each other, for which the geom field looks totally different.
I guess this is not the way to check for the unicity of the geom, so what would be the proper way?
I run PostgreSQL 9.4 and PostGIS 2.2
UNIQUE CONSTAINTis arguably still not the way to check for geometry uniqueness, and I might be wrong here, I´d say the culprit is how, in PostgreSQL < 9.5, the=operator works on geometries (i.a. here), since the uniqueness of that constraint is enforced via (unique) btree index, and thus the=will be used on the geometry type. you could try to use that constraint on a newbyteacolumn with the value ofST_AsBinary(geom)or use a trigger to compare withST_Equals. – geozelot Jun 18 '18 at 11:44