             FROM cityobject_genericattrib cga, genattrib g
             WHERE cga.parent_genattrib_id = g.id
       )
-      SELECT citydb_pkg.batch_delete_geometry(batch.ids) INTO dummy_array FROM (
-        SELECT array_agg(id) AS ids
-          FROM genattrib
-          GROUP BY level ORDER BY level DESC
-      ) batch;
+      SELECT citydb_pkg.batch_delete_genericattribs(id ORDER BY level DESC) INTO dummy_array
+        FROM genattrib;
     ELSE
       -- recursive update of nested attributes
       FOR member_rec IN
         WITH RECURSIVE parts (id, parent_id, root_id) AS (
-           SELECT id, genattrib_parent_id::integer AS parent_id, 
-             CASE WHEN root_genattrib_id = $1 THEN id ELSE root_genattrib_id END AS root_id
-             FROM cityobject_genericattrib
-             WHERE parent_genattrib_id = $1
-           UNION ALL
-             SELECT part.id, part.parent_genattrib_id AS parent_id, p.root_id
-               FROM cityobject_genericattrib part, parts p 
-               WHERE part.parent_genattrib_id = p.id
+          SELECT id, genattrib_parent_id::integer AS parent_id, 
+            CASE WHEN root_genattrib_id = $1 THEN id ELSE root_genattrib_id END AS root_id
+            FROM cityobject_genericattrib
+            WHERE parent_genattrib_id = $1
+          UNION ALL
+            SELECT part.id, part.parent_genattrib_id AS parent_id, p.root_id
+              FROM cityobject_genericattrib part, parts p 
+              WHERE part.parent_genattrib_id = p.id
         )
         SELECT id, parent_id, root_id FROM parts
       LOOP

      FROM surface_geometry sg, geometry g
      WHERE sg.parent_id = g.id
)
SELECT array_agg(g.g_id) AS result_array FROM (
  SELECT unnest(citydb_pkg.batch_delete_geometry(batch.ids)) AS g_id FROM (
    SELECT array_agg(id) AS ids
      FROM geometry
      GROUP BY level ORDER BY level DESC
  ) batch
) g;
$$
LANGUAGE sql STRICT;

$$
DECLARE
  deleted_id int;
  address_array int[] := '{}';
BEGIN
  -- delete bridge parts
  PERFORM citydb_pkg.delete_bridges(id)
    FROM bridge
    WHERE bridge_parent_id = $1
      AND id != $1;

  -- delete rooms
  PERFORM citydb_pkg.delete_bridge_rooms(id)
