feat: add bin/join-rts-srvcs-trps.sh
This commit is contained in:
parent
81adc47377
commit
45b6aa1a9b
|
@ -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.sql -d $DB_NAME -v schema=$DB_SCHEMA
|
||||
#
|
||||
echo "Done."
|
||||
#done.
|
|
@ -0,0 +1,9 @@
|
|||
-- 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;
|
||||
SET search_path to :schema, 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 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 ORDER BY rts.route_id, trps.trip_id;
|
Loading…
Reference in New Issue