     || E'\nBEGIN'
     || pre_block
     || E'\n  -- delete '||$1||'s'
-    || E'\n  RETURN '||schema_name||'.delete_' ||citydb_pkg.get_short_name($1)|| E'($1);'
+    || E'\n  RETURN '||$2||'.delete_' ||citydb_pkg.get_short_name($1)|| E'($1);'
     || E'\nEND;'
     || E'\n$body$'
     || E'\nLANGUAGE plpgsql STRICT';

    || E'\nBEGIN'
    || pre_block
    || E'\n  -- delete '||$1||'s'
    || E'\n  RETURN QUERY\n    SELECT '||schema_name||'.delete_' ||citydb_pkg.get_short_name($1)|| E'($1);'
    || E'\nEND;'
    || E'\n$body$'
    || E'\nLANGUAGE plpgsql STRICT';

  LOOP
    IF vars IS NULL THEN
      vars := '';
      child_ref_block := '';
      ref_block := '';
    END IF;

    IF (
