Mercurial > gemma
comparison pkg/imports/agm.go @ 3389:45a629a3a8b8
Fix constraints on relationship between gauges and measurements/predictions
measure_date is the time of measurement, not date_issue.
There can be only one measurement at a time for a gauge location,
independently of gauge versions with differing validity.
The 'measure_date' of a prediction can well be beyond the validity
of the gauge, since a new gauge version might appear within the
time range of the forecast.
There can be only one prediction at a time per date of issue,
independently of gauge versions with differing validity.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 22 May 2019 16:44:13 +0200 |
parents | ec6163c6687d |
children | 45483dd0d801 |
comparison
equal
deleted
inserted
replaced
3388:1876b204b004 | 3389:45a629a3a8b8 |
---|---|
73 ), | 73 ), |
74 to_delete AS ( | 74 to_delete AS ( |
75 SELECT o.id AS id | 75 SELECT o.id AS id |
76 FROM waterway.gauge_measurements o | 76 FROM waterway.gauge_measurements o |
77 JOIN waterway.gauge_measurements n | 77 JOIN waterway.gauge_measurements n |
78 USING (location, validity, measure_date) | 78 USING (location, measure_date) |
79 WHERE n.id IN (SELECT key FROM staged) | 79 WHERE n.id IN (SELECT key FROM staged) |
80 AND o.id NOT IN (SELECT key FROM staged) | 80 AND o.id NOT IN (SELECT key FROM staged) |
81 ) | 81 ) |
82 DELETE FROM waterway.gauge_measurements WHERE id IN (SELECT id from to_delete)` | 82 DELETE FROM waterway.gauge_measurements WHERE id IN (SELECT id from to_delete)` |
83 | 83 |