PHP Rocks
PROCEDURE call über Trigger - Verständnisfrage - Druckversion

+- PHP Rocks (https://www.php-rocks.de)
+-- Forum: Datenbanken (https://www.php-rocks.de/https://www.php-rocks.de/forum/6-datenbanken.html)
+--- Forum: PostgreSQL (https://www.php-rocks.de/https://www.php-rocks.de/forum/8-postgresql.html)
+--- Thema: PROCEDURE call über Trigger - Verständnisfrage (/https://www.php-rocks.de/thema/70-procedure-call-ueber-trigger-verstaendnisfrage.html)



PROCEDURE call über Trigger - Verständnisfrage - Arne Drews - 27.08.2015

Hallo,

Mal sehen, ob ich hier auch pgSQL-Profis finde.  Big Grin

Ich möchte in einem Trigger eine PROCEDURE aufrufen, was ja mit EXEC kein Problem darstellen sollte.
Allerdings habe ich mir dazu auch die Doku angesehen: http://www.postgresql.org/docs/9.4/static/plpgsql-trigger.html
PG-Doku schrieb:
Code:
CREATE TABLE emp (
   empname text,
   salary integer,
   last_date timestamp,
   last_user text
);

CREATE FUNCTION emp_stamp() RETURNS trigger AS $emp_stamp$
   BEGIN
       -- Check that empname and salary are given
       IF NEW.empname IS NULL THEN
           RAISE EXCEPTION 'empname cannot be null';
       END IF;
       IF NEW.salary IS NULL THEN
           RAISE EXCEPTION '% cannot have null salary', NEW.empname;
       END IF;

       -- Who works for us when she must pay for it?
       IF NEW.salary < 0 THEN
           RAISE EXCEPTION '% cannot have a negative salary', NEW.empname;
       END IF;

       -- Remember who changed the payroll when
       NEW.last_date := current_timestamp;
       NEW.last_user := current_user;
       RETURN NEW;
   END;
$emp_stamp$ LANGUAGE plpgsql;

CREATE TRIGGER emp_stamp BEFORE INSERT OR UPDATE ON emp
   FOR EACH ROW EXECUTE PROCEDURE emp_stamp();
Soweit also nichts spannendes.

Meine Frage ist, ob diese Zeile notwendig ist und warum genau?
Code:
$emp_stamp$ LANGUAGE plpgsql;