DROP TABLE IF EXISTS :schema.links CASCADE;

CREATE UNLOGGED TABLE :schema.links AS
SELECT
  h.id,
  h.hwtype AS highway,
  h.surface,
  h.oneway,
  h.maxspeed,
  ST_Length(h.geom) AS length,
  COALESCE(NULLIF(h.name, ''), NULLIF(h.hwtype, ''), 'Unnamed road') AS name,
  h.geom AS geometry
FROM :schema.ardok_highways h;

CREATE INDEX links_geom_idx ON :schema.links USING GIST (geometry);
