extract(epoch from checkin_time) :: int8 as checkin_ts,
extract(epoch from sched_departure) :: int8 as sched_dep_ts,
extract(epoch from real_departure) :: int8 as real_dep_ts,
extract(epoch from real_departure - sched_departure) :: int8 as delay_dep,
checkin_station_id as dep_eva,
dep_station.ds100 as dep_ds100,
dep_station.name as dep_name,
dep_station.lat as dep_lat,
dep_station.lon as dep_lon,
dep_station_external_id.external_id as dep_external_id,
extract(epoch from checkout_time) :: int8 as checkout_ts,
extract(epoch from sched_arrival) :: int8 as sched_arr_ts,
extract(epoch from real_arrival) :: int8 as real_arr_ts,
extract(epoch from real_arrival - sched_arrival) :: int8 as delay_arr,
checkout_station_id as arr_eva,
arr_station.ds100 as arr_ds100,
arr_station.name as arr_name,
arr_station.lat as arr_lat,
arr_station.lon as arr_lon,
arr_station_external_id.external_id as arr_external_id,
extract(epoch from sched_arrival - sched_departure) :: int8 as sched_duration,
extract(epoch from real_arrival - real_departure) :: int8 as rt_duration,
polylines.polyline as polyline,
visibility,
coalesce(visibility, users.public_level & 127) as effective_visibility,
cancelled, edited, route, messages, user_data,
dep_platform, arr_platform
from journeys
left join polylines on polylines.id = polyline_id
left join users on users.id = user_id
left join stations as dep_station on checkin_station_id = dep_station.eva and journeys.backend_id = dep_station.source
left join stations as arr_station on checkout_station_id = arr_station.eva and journeys.backend_id = arr_station.source
left join stations_external_ids as dep_station_external_id on checkin_station_id = dep_station_external_id.eva and journeys.backend_id = dep_station_external_id.backend_id
left join stations_external_ids as arr_station_external_id on checkout_station_id = arr_station_external_id.eva and journeys.backend_id = arr_station_external_id.backend_id
left join backends as backend on journeys.backend_id = backend.id