I've been fighting this for quite a long time and everytime I think I got it, I got it wrong actually.
What's the trouble
See picture below. As a result of line buffers I got overlaps that need to be removed on buffer ends. I'm looking for a way to tell PostGIS which overlaps should be differed from which buffer. I ended up with topological incorrect polygons several times.
If you wish, grab the table dump.
I get all the overlaps with this query:
SELECT DISTINCT (ST_Dump(ST_Intersection(a.geom, ST_Union(b.geom)))).geom geom FROM test a, test b WHERE a.geom && b.geom AND ST_Intersects(a.geom, b.geom) AND NOT ST_Equals(a.geom, b.geom) GROUP BY a.geom
No idea how to proceed.
UPDATE I need to remove overlaps so buffers face each other just fine with no white space. E.g. if two buffers overlap, the overlapping portion of space should be removed just from the one of those two.