feat: add bin/join-rts-srvcs-trps-pdts.sh

This commit is contained in:
dancingCycle 2023-12-15 23:24:34 +01:00
parent cbf3f42905
commit 172f5fa892
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#!/bin/sh
#
echo "Started..."
#Started...
#
# special variable $# is the number of arguments
if [ $# -lt 3 ] ; then
echo 'Call ./<script> <db name> <db user> <db schema>'
exit 1
fi
#
DB_NAME="$1"
echo "DB_NAME: ${DB_NAME}"
DB_USER="$2"
echo "DB_USER: ${DB_USER}"
DB_SCHEMA="$3"
echo "DB_SCHEMA: ${DB_SCHEMA}"
#
psql -h localhost -p 5432 -U $DB_USER -f ./sql/join-rts-srvcs-trps-pdts.sql -d $DB_NAME -v schema=$DB_SCHEMA
#
echo "Done."
#done.

View File

@ -0,0 +1,10 @@
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
CREATE SCHEMA IF NOT EXISTS :schema;
CREATE SCHEMA IF NOT EXISTS :schema_gtfsr;
SET search_path to :schema, :schema_gtfsr, public;
---create view
CREATE OR REPLACE VIEW :schema.vw_join_rts_trps_srvcs AS
SELECT rts.route_id, rts.route_short_name, rts.route_long_name, trps.service_id, trps.trip_id, trps.trip_short_name, trps.trip_headsign, srvcs.dates, pdts.timestamp_pgsql FROM :schema.trips AS trps LEFT JOIN :schema.routes AS rts ON trps.route_id = rts.route_id LEFT JOIN :schema.services AS srvcs ON trps.service_id = srvcs.service_id LEFT JOIN :schema_gtfsr.trip_updates AS pdts ON trps.route_id = pdts.trip_route_id AND trps.trip_id = pdts.trip_trip_id ORDER BY rts.route_id, trps.trip_id;