[repost] trigger update time - Mailing list pgsql-novice

From Rory Campbell-Lange
Subject [repost] trigger update time
Date
Msg-id 20020619083634.GB7752@campbell-lange.net
Whole thread Raw
Responses Re: [repost] trigger update time  (Manfred Koizar <mkoi-pg@aon.at>)
Re: [repost] trigger update time  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
I hope I'm not transgressing the boundaries of list etiquette - I didn't
get a response to my first message so I've retitled it and resubmitted
it here.

I am trying to update a timestamp value in a related table using
functions and triggers, but failing miserably! I'd be grateful for some
help.

-----------------------------------------------------------------------

CREATE TABLE "a" (
    "id" SERIAL,
    "tstamp" timestamp
);

CREATE TABLE "b" (
    "id" SERIAL,
    "a_id" integer,
    "tstamp" timestamp default current_timestamp.
);


CREATE FUNCTION "fnTU" () RETURNS opaque AS 'BEGIN
UPDATE a SET tstamp = new.tstamp;
WHERE new.a_id = id;
RETURN new;
END' LANGUAGE 'plpgsql';

CREATE TRIGGER "trgTU" AFTER INSERT ON "b"  FOR EACH ROW EXECUTE
PROCEDURE "fnTU" ();


--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>

pgsql-novice by date:

Previous
From: John Taylor
Date:
Subject: Re: Which indexes to drop
Next
From: Ron Johnson
Date:
Subject: Re: Which indexes to drop