diff flys-backend/doc/schema/postgresql.sql @ 476:77f337650211

Added a view 'wst_value_table' which aggregates the data to build w/q value tables. flys-backend/trunk@1723 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 18 Apr 2011 15:52:53 +0000
parents 3570e4af8cb2
children b35c5dc0f8b7
line wrap: on
line diff
--- a/flys-backend/doc/schema/postgresql.sql	Mon Apr 18 13:34:07 2011 +0000
+++ b/flys-backend/doc/schema/postgresql.sql	Mon Apr 18 15:52:53 2011 +0000
@@ -194,4 +194,25 @@
     UNIQUE (wst_column_id, wst_q_range_id)
 );
 
+CREATE VIEW wst_value_table AS
+    SELECT wcv.position AS position,
+           w,
+           (SELECT q
+            FROM   wst_column_q_ranges wcqr
+                   JOIN wst_q_ranges wqr
+                     ON wcqr.wst_q_range_id = wqr.id
+                   JOIN ranges r
+                     ON r.id = wqr.range_id
+            WHERE  wcqr.wst_column_id = wc.id
+                   AND wcv.position BETWEEN r.a AND r.b) AS q,
+           wc.position                                   AS column_pos,
+           w.id                                          AS wst_id
+    FROM   wst_column_values wcv
+           JOIN wst_columns wc
+             ON wcv.wst_column_id = wc.id
+           JOIN wsts w
+             ON wc.wst_id = w.id
+    ORDER  BY wcv.position ASC,
+          wc.position DESC;
+
 COMMIT;

http://dive4elements.wald.intevation.org