Trigger and Trigger function.
От | Matt Iskra |
---|---|
Тема | Trigger and Trigger function. |
Дата | |
Msg-id | s2b1a145.070@gwia обсуждение исходный текст |
Ответы |
Re: Trigger and Trigger function.
|
Список | pgsql-novice |
Howdy y'all. I have been trying to get a trigger and trigger function working. I have looked at the docs, copied the examples, and I stillcannot get this to work. So, now I try you guys/gals. My test environment: Windows XP Pro (on my laptop) User account Postgre, with non-admin premissions PostgreSQL 8.0.3 (via msi) Installed the pl/pgsql language I created a test database, named testdb. I created a schema called oc along with its own tablespace. The table creates OK,but the function that is going to be called by the trigger gets a syntex error on the second line, where the functionis named. My purpose is to get the last_touch field in the table to always have the timestamp when the record was inserted or updated. Thanks for the use of your expertise. Source code follows. --Matthe /****************************************/ CREATE TABLE oc.optical ( id serial NOT NULL, created timestamp NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone, last_touch timestamp NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone, file varchar(30), CONSTRAINT optical_pk PRIMARY KEY (id) USING INDEX TABLESPACE oc ) WITHOUT OIDS TABLESPACE oc; ALTER TABLE oc.optical OWNER TO oc; CREATE FUNCTION oc.upd_last_touch() <-- syntex error here RETURNS TRIGGER AS $upd_last_touch$ BEGIN IF TG_NAME = 'optical_trig' THEN UPDATE optical SET NEW.last_touch = current_timestamp WHERE NEW.id = id; END IF; END; $upd_last_touch$ LANGUAGE 'plpgsql' VOLATILE; ALTER FUNCTION oc.optical_upd() OWNER TO oc; CREATE TRIGGER optical_trig BEFORE UPDATE ON optical FOR EACH ROW EXECUTE PROCEDURE upd_last_touch(); /****************************************/ CONFIDENTIALITY NOTICE: This communication with its contents may contain confidential and/or legally privileged information. It is solely for the use of the intended recipient(s). Unauthorized interception, review, use or disclosure is prohibited and may violate applicable laws including the Electronic Communications Privacy Act. If you are not the intended recipient, please contact the sender and destroy all copies of the communication.
В списке pgsql-novice по дате отправления: