diff schema/gemma.sql @ 4909:6f244b5eb716 fairway-marks-import

Use table inheritance to define common fairway marks attributes
author Tom Gottfried <tom@intevation.de>
date Mon, 10 Feb 2020 14:56:43 +0100
parents 638a61fb881b
children bfd8ef836998
line wrap: on
line diff
--- a/schema/gemma.sql	Fri Feb 07 19:42:09 2020 +0100
+++ b/schema/gemma.sql	Mon Feb 10 14:56:43 2020 +0100
@@ -841,8 +841,9 @@
             OR value_lifetime IS NOT NULL)
     )
 
+    -- Attributes common to all fairway marks
+    -- according to IENC feature catalogue
     CREATE TABLE fairway_marks (
-        id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
         geom geography(POINT, 4326) NOT NULL,
         datsta varchar,
         datend varchar,
@@ -856,21 +857,28 @@
         picrep varchar,
         txtdsc varchar,
         sordat varchar,
-        sorind varchar,
+        sorind varchar
+    )
+
+    -- Additional attributes for IENC features BCNLAT/bcnlat
+    CREATE TABLE fairway_marks_bcnlat (
+        id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
         colour varchar,
         colpat varchar,
         condtn int,
         bcnshp int,
         catlam int,
         dirimp smallint REFERENCES dirimps
-    )
+    ) INHERITS (fairway_marks)
     -- Prevent identical entries using composite type comparison
     -- (i.e. considering two NULL values in a field equal):
-    CREATE UNIQUE INDEX fairway_marks_distinct_rows ON fairway_marks
-        ((CAST((0, geom,
-            datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom,
-            scamin, picrep, txtdsc, sordat, sorind, colour, colpat, condtn,
-            bcnshp, catlam, dirimp) AS fairway_marks)
+    CREATE UNIQUE INDEX fairway_marks_bcnlat_distinct_rows
+        ON fairway_marks_bcnlat
+        ((CAST((geom,
+                datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom,
+                scamin, picrep, txtdsc, sordat, sorind,
+                0, colour, colpat, condtn, bcnshp, catlam, dirimp
+            ) AS fairway_marks_bcnlat)
         ))
 ;