Mercurial > dive4elements > river
comparison backend/doc/schema/postgresql.sql @ 6078:176664f84d86
Schema change: view for WSTs which deales with multiple ranges matching station (issues 1315 and 1296)
author | Tom Gottfried <tom.gottfried@intevation.de> |
---|---|
date | Thu, 23 May 2013 17:32:20 +0200 |
parents | d12f920bbf00 |
children | 6cdb3ee687a9 |
comparison
equal
deleted
inserted
replaced
6076:c97d003fd127 | 6078:176664f84d86 |
---|---|
241 | 241 |
242 UNIQUE (wst_column_id, wst_q_range_id) | 242 UNIQUE (wst_column_id, wst_q_range_id) |
243 ); | 243 ); |
244 | 244 |
245 CREATE VIEW wst_value_table AS | 245 CREATE VIEW wst_value_table AS |
246 SELECT wcv.position AS position, | 246 SELECT |
247 w, | 247 wcv.position AS position, |
248 (SELECT q | 248 w, |
249 FROM wst_column_q_ranges wcqr | 249 q, |
250 JOIN wst_q_ranges wqr | 250 wc.position AS column_pos, |
251 ON wcqr.wst_q_range_id = wqr.id | 251 w.id AS wst_id |
252 JOIN ranges r | 252 FROM wsts w |
253 ON r.id = wqr.range_id | 253 JOIN wst_columns wc |
254 WHERE wcqr.wst_column_id = wc.id | 254 ON wc.wst_id=w.id |
255 AND wcv.position BETWEEN r.a AND r.b) AS q, | 255 JOIN wst_column_q_ranges wcqr |
256 wc.position AS column_pos, | 256 ON wcqr.wst_column_id=wc.id |
257 w.id AS wst_id | 257 JOIN wst_q_ranges wqr |
258 FROM wst_column_values wcv | 258 ON wcqr.wst_q_range_id=wqr.id |
259 JOIN wst_columns wc | 259 JOIN ranges r |
260 ON wcv.wst_column_id = wc.id | 260 ON wqr.range_id=r.id |
261 JOIN wsts w | 261 JOIN wst_column_values wcv |
262 ON wc.wst_id = w.id | 262 ON wcv.wst_column_id=wc.id AND wcv.position between r.a and r.b; |
263 ORDER BY wcv.position ASC, | 263 ORDER BY wcv.position ASC, |
264 wc.position DESC; | 264 wc.position DESC; |
265 | 265 |
266 -- view to select the w values of a WST | 266 -- view to select the w values of a WST |
267 CREATE VIEW wst_w_values AS | 267 CREATE VIEW wst_w_values AS |
268 SELECT wcv."position" AS km, | 268 SELECT wcv."position" AS km, |
269 wcv.w AS w, | 269 wcv.w AS w, |