How to do recursive PostgreSQL query for merging polygons by percent overlap

I'm using this answer for merging overlapping polygons where they overlap by a certain amount. In the comments there is a mention of doing it recursively and after studying the suggestion its still hard for me to wrap my mind around how to implement it for this example. How could I implement this query recursively?

The query:

``````WITH a AS
(SELECT geometry_id, geometry_geometry::geometry AS geometry_geometry FROM target_geometry),
b AS (select geometry_id, geometry_geometry::geometry AS geometry_geometry FROM target_geometry)
SELECT a.geometry_id, b.geometry_id, ST_Area(a.geometry_geometry::geometry), ST_Area(b.geometry_geometry::geometry)
, 100*(ST_Area(ST_Intersection(a.geometry_geometry::geometry, b.geometry_geometry::geometry))/LEAST(ST_Area(a.geometry_geometry::geometry), ST_Area(b.geometry_geometry::geometry)))::numeric(5,2)
as pct_overlap
, ST_Union(a.geometry_geometry::geometry, b.geometry_geometry::geometry) as new_shape
FROM a
JOIN b ON a.geometry_geometry::geometry && b.geometry_geometry::geometry AND ST_Intersects(a.geometry_geometry::geometry, b.geometry_geometry::geometry)
WHERE a.geometry_id <> b.geometry_id AND
30 <= 100*(ST_Area(ST_Intersection(a.geometry_geometry::geometry, b.geometry_geometry::geometry))
/LEAST(ST_Area(a.geometry_geometry::geometry), ST_Area(b.geometry_geometry::geometry)))::numeric(5,2)

;
``````