CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;

---create view
CREATE OR REPLACE VIEW :schema.vw_distances AS
SELECT relation_id, en_from_name, en_from_lon, en_from_lat, en_to_name, en_to_lon, en_to_lat, ST_DistanceSphere(ST_MakePoint(en_from_lon, en_from_lat), ST_MakePoint(en_to_lon, en_to_lat)) AS dist FROM tbl_relations_coord;

---create table
CREATE TABLE IF NOT EXISTS :schema.tbl_distances AS SELECT * FROM :schema.vw_distances;
