Mercurial > gemma
diff schema/geoserver_views.sql @ 3302:ec6163c6687d
'Historicise' gauges on import
Gauge data sets will be updated or a new version will be inserted
depending on temporal validity and a timestamp marking the last
update in the RIS-Index of a data set. The trigger on date_info is
removed because the value is actually an attribut coming from the
RIS-Index.
Gauge measurements and predictions are associated to the version with
matching temporal validity. Bottlenecks are always associated to the
actual version of the gauge, although this might change as soon as
bottlenecks are 'historicised', too.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 16 May 2019 18:41:43 +0200 |
parents | 831193935739 |
children | b90b17d0b5a9 |
line wrap: on
line diff
--- a/schema/geoserver_views.sql Thu May 16 17:22:33 2019 +0200 +++ b/schema/geoserver_views.sql Thu May 16 18:41:43 2019 +0200 @@ -16,8 +16,9 @@ AS reference_water_levels FROM waterway.gauges g LEFT JOIN waterway.gauges_reference_water_levels r - ON r.gauge_id = g.location - GROUP BY g.location; + USING (location, validity) + WHERE NOT g.erased + GROUP BY g.location, g.validity; CREATE OR REPLACE VIEW waterway.distance_marks_geoserver AS SELECT location_code, @@ -44,9 +45,9 @@ FROM waterway.fairway_availability ORDER BY bottleneck_id, date_info DESC), waterlevel_latest AS ( - SELECT DISTINCT ON (fk_gauge_id) fk_gauge_id, water_level + SELECT DISTINCT ON (location) location, water_level FROM waterway.gauge_measurements - ORDER BY fk_gauge_id, measure_date DESC) + ORDER BY location, measure_date DESC) SELECT b.id, b.bottleneck_id, @@ -71,14 +72,16 @@ wl.water_level AS gm_waterlevel FROM waterway.bottlenecks b LEFT JOIN waterway.gauges g - ON b.fk_g_fid = g.location + ON b.gauge_location = g.location AND b.gauge_validity = g.validity LEFT JOIN waterway.gauges_reference_water_levels r - ON g.location = r.gauge_id + USING (location, validity) LEFT JOIN fairway_availability_latest fal ON b.id = fal.bottleneck_id LEFT JOIN waterlevel_latest wl - ON b.fk_g_fid = wl.fk_gauge_id - GROUP BY b.id, g.location, fal.date_info, fal.critical, wl.water_level; + USING (location) + WHERE NOT g.erased + GROUP BY b.id, g.location, g.validity, + fal.date_info, fal.critical, wl.water_level; CREATE OR REPLACE VIEW waterway.stretches_geoserver AS SELECT