From e2d81c097eaa63516f70fb6808e28d440a4b0838 Mon Sep 17 00:00:00 2001 From: Jesse Jaara Date: Thu, 7 Nov 2024 13:42:28 +0200 Subject: [PATCH] Add quay publicCode & streetAddress to stop_place_newest_version --- ...R__view_for_newest_stop_place_versions.sql | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/resources/db/migration/R__view_for_newest_stop_place_versions.sql b/src/main/resources/db/migration/R__view_for_newest_stop_place_versions.sql index 601ba44a9..c0f7149bf 100644 --- a/src/main/resources/db/migration/R__view_for_newest_stop_place_versions.sql +++ b/src/main/resources/db/migration/R__view_for_newest_stop_place_versions.sql @@ -1,5 +1,19 @@ -create or replace view stop_place_newest_version as - select distinct on (netex_id) * - from stop_place - order by netex_id, version desc; +DROP VIEW IF EXISTS stop_place_newest_version; + +CREATE VIEW stop_place_newest_version AS +SELECT DISTINCT ON (sp.netex_id) + sp.*, + quay.public_code AS quay_public_code, + address_value.items as street_address + +FROM stop_place AS sp + + INNER JOIN stop_place_quays AS spq ON sp.id = spq.stop_place_id + INNER JOIN quay ON spq.quays_id = quay.id + + LEFT JOIN stop_place_key_values AS spkv ON + sp.id = spkv.stop_place_id AND spkv.key_values_key = 'streetAddress' + LEFT JOIN value_items AS address_value ON spkv.key_values_id = address_value.value_id + +ORDER BY netex_id ASC, version DESC