   parts_array int[] := '{}';
   address_array int[] := '{}';
 BEGIN
-  -- delete parts
-  WITH RECURSIVE part(id, bridge_parent_id, level) AS (
-    SELECT id, bridge_parent_id, 1 AS level 
-      FROM bridge b, (
-        SELECT unnest($1) AS b_id
-      ) a
-      WHERE b.id = a.b_id
-    UNION ALL
-      SELECT b.id, b.bridge_parent_id, p.level + 1 AS level 
-        FROM bridge b, part p
-        WHERE b.bridge_parent_id = p.id
-  )
-  SELECT array_agg(bp.g_id) INTO parts_array FROM (
-    SELECT unnest(citydb_pkg.delete_bridges(batch.ids)) AS g_id FROM (
-      SELECT array_agg(id) AS ids
-        FROM part
-        WHERE level > 1
-        GROUP BY level ORDER BY level DESC
-    ) batch
-  ) bp;
+  -- delete bridge parts
+  PERFORM citydb_pkg.delete_bridges(b.id) INTO parts_array
+    FROM bridge b, (
+      SELECT unnest($1) AS b_id
+    ) a   
+    WHERE b.bridge_parent_id = b_id
+      AND b.id != b_id;
 
   -- delete bridge rooms
   PERFORM citydb_pkg.delete_bridge_rooms(r.id)

  -- delete entries from surface_geometry table
  WITH delete_geometry AS (
    DELETE FROM surface_geometry sg USING (
      SELECT unnest($1) AS sg_id
    ) a
    WHERE sg.id = a.sg_id
    RETURNING sg.id

      FROM cityobject_genericattrib cga, genattrib g
      WHERE cga.parent_genattrib_id = g.id
)
SELECT citydb_pkg.batch_delete_genericattribs(g.id ORDER BY g.level DESC) AS result_array FROM (
  SELECT DISTINCT ON (id) id, level
    FROM genattrib
    ORDER BY id DESC, level DESC
) g;
$$
LANGUAGE sql STRICT;
