gtfs/sql/update.sql

31 lines
1.2 KiB
SQL

---clean up schema
DROP SCHEMA IF EXISTS :schema CASCADE;
CREATE SCHEMA IF NOT EXISTS :schema;
CREATE SCHEMA IF NOT EXISTS :schema_gtfs;
SET search_path to :schema, :schema_gtfs, public;
---get subset of stops with location type 0
---create views
CREATE OR REPLACE VIEW :schema.vw_stops_lt_0 AS
SELECT * FROM :schema_gtfs.stops WHERE location_type=0;
---create tables
CREATE TABLE IF NOT EXISTS :schema.tbl_stops_lt_0 AS SELECT stop_id,stop_name,stop_lat,stop_lon,the_geom FROM :schema.vw_stops_lt_0;
---get subset of stops that do not comply with a proper Global ID
---create views
CREATE OR REPLACE VIEW :schema.vw_stops_not_dhid AS
SELECT * FROM :schema_gtfs.stops WHERE stop_id NOT LIKE '%:%:%' ORDER BY stop_id;
CREATE OR REPLACE VIEW :schema.vw_stops_lt_0_not_dhid AS
SELECT * FROM :schema.tbl_stops_lt_0 WHERE stop_id NOT LIKE '%:%:%' ORDER BY stop_id;
---create tables
CREATE TABLE IF NOT EXISTS :schema.tbl_stops_not_dhid AS SELECT stop_id,stop_name,stop_lat,stop_lon,the_geom FROM :schema.vw_stops_not_dhid;
CREATE TABLE IF NOT EXISTS :schema.tbl_stops_lt_0_not_dhid AS SELECT stop_id,stop_name,stop_lat,stop_lon,the_geom FROM :schema.vw_stops_lt_0_not_dhid;