-- Määra skeema muutuja
SET myvars.schema TO :'schema';

DO $$
DECLARE
  r RECORD;
  schema_name TEXT := current_setting('myvars.schema');
BEGIN
  FOR r IN
    EXECUTE format($f$
      SELECT tablename
      FROM pg_tables
      WHERE schemaname = %L
        AND tablename LIKE 'links_%%'
    $f$, schema_name)
  LOOP
    EXECUTE format('DROP TABLE IF EXISTS %I.%I CASCADE;', schema_name, r.tablename);
    RAISE NOTICE 'Kustutatud: %.%', schema_name, r.tablename;
  END LOOP;
END
$$;

-- Tabelite kustutamine
DROP TABLE IF EXISTS :schema._noded_geom;
DROP TABLE IF EXISTS :schema._raw_segments;
DROP TABLE IF EXISTS :schema.links_vertices;

