From: | "Mike Baroukh" <mbaroukh(at)i-panema(dot)fr> |
---|---|
To: | <craig(dot)may(at)s2(dot)enthdimension(dot)com(dot)au>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Trigger |
Date: | 2000-09-06 10:24:15 |
Message-ID: | 028b01c017ec$9bce6790$0102000a@ipanema.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
There is a sample in postgres documentation. (See below).
the only problem is for using langage plpgsql.
If it is not understand by your database, you must use command
createlang plpgsql dbname
as the owner of the database.
CREATE TABLE emp (
empname text,
salary int4,
last_date datetime,
last_user name);
CREATE FUNCTION emp_stamp () RETURNS OPAQUE AS
BEGIN
-- Check that empname and salary are given
IF NEW.empname ISNULL THEN
RAISE EXCEPTION ''empname cannot be NULL value'';
END IF;
IF NEW.salary ISNULL THEN
RAISE EXCEPTION ''% cannot have NULL salary'', NEW.empname;
END IF;
-- Who works for us when she must pay for?
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 := ''now'';
NEW.last_user := getpgusername();
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER emp_stamp BEFORE INSERT OR UPDATE ON emp
FOR EACH ROW EXECUTE PROCEDURE emp_stamp();
----- Original Message -----
From: Craig May <craig(dot)may(at)s2(dot)enthdimension(dot)com(dot)au>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Wednesday, September 06, 2000 10:27 PM
Subject: [SQL] Trigger
>
> Could someone send me a quick example of a trigger.
>
From | Date | Subject | |
---|---|---|---|
Next Message | Chris Ryan | 2000-09-06 12:18:18 | Re: Trigger |
Previous Message | Karel Zak | 2000-09-06 07:01:13 | Re: 8K Limit, and Replication |