Skip to content

Instantly share code, notes, and snippets.

@fitnr
Last active November 10, 2019 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitnr/5889d55c9d0bb5ada9c79cd51a54de74 to your computer and use it in GitHub Desktop.
Save fitnr/5889d55c9d0bb5ada9c79cd51a54de74 to your computer and use it in GitHub Desktop.
Example of inserting missing service_id into a GTFS
INSERT INTO gtfs.calendar (feed_index, service_id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date)
SELECT a.feed_index, a.service_id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date
FROM (
SELECT feed_index, service_id
FROM gtfs.trips a
LEFT JOIN gtfs.calendar b using (feed_index, service_id)
WHERE COALESCE(b.monday, b.friday) IS NULL
GROUP BY feed_index, service_id
) a
INNER JOIN gtfs.calendar b ON a.feed_index = b.feed_index AND (
replace(a.service_id, '-BM', '-SDon-BM') = b.service_id OR
a.service_id || '-SDon' = b.service_id
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment