[Lada-commits] [PATCH 1 of 4] Added trigger to fill stammdaten.ort attributes

Wald Commits scm-commit at wald.intevation.org
Wed Nov 16 15:59:28 CET 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1479308203 -3600
# Node ID 60b91dbb98cc6b6d4a5124fa90a2c9566c928ecc
# Parent  7c510615a4e826f2617b980d76086d7d9fd2ccbc
Added trigger to fill stammdaten.ort attributes.

diff -r 7c510615a4e8 -r 60b91dbb98cc db_schema/stammdaten_schema.sql
--- a/db_schema/stammdaten_schema.sql	Thu Nov 10 13:49:31 2016 +0100
+++ b/db_schema/stammdaten_schema.sql	Wed Nov 16 15:56:43 2016 +0100
@@ -14,6 +14,24 @@
 
 SET search_path = stammdaten, pg_catalog;
 
+CREATE FUNCTION set_ort_id() RETURNS trigger
+    LANGUAGE plpgsql
+    AS $$
+    BEGIN
+        value = '#'::text || lpad((NEW.id::character varying)::text, 9, '0'::text);
+        IF NEW.ort_id IS NULL THEN
+            NEW.ort_id = value;
+        END IF;
+        IF NEW.langtext IS NULL THEN
+            NEW.langtext = value;
+        END IF;
+        IF NEW.kurztext IS NULL THEN
+            NEW.kurztext = value;
+        END IF;
+        RETURN NEW;
+    END;
+$$;
+
 CREATE FUNCTION update_letzte_aenderung() RETURNS trigger
     LANGUAGE plpgsql
     AS $$
@@ -450,6 +468,7 @@
 );
 
 CREATE TRIGGER letzte_aenderung_ort BEFORE UPDATE ON ort FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung();
+CREATE TRIGGER set_ort_id_ort BEFORE INSERT ON ort FOR EACH ROW EXECUTE PROCEDURE set_ort_id();
 
 ALTER TABLE ONLY ort
     ADD CONSTRAINT ort_kta_fkey FOREIGN KEY (anlage_id) REFERENCES kta(id);


More information about the Lada-commits mailing list