It's really clear how to apply ST_Intersection when you have only two geometries. But I am struggling with the situation where you have N>2 shapes and you want to compute a single one that represents intersection of all of them as a single geometry.
With the help of ST_Intersection: Intersection of all geometries in a table I can get intersections for all pairs of geometries in a single table. But it is not exactly what I am trying to achieve though.
Let me try to illustrate the problem. What I have is this (simplified to only three geometries):
But what I am after is this:
I have over 5000 shapes in the table, so obviously I can't specify them explicitly.
I imagine a loop could be a solution, something like:
result = union(geometries) for geom in geometries: result = intersection(result, geom)
How would you achieve this with PostgreSQL/PostGIS?