Skip site navigation (1) Skip section navigation (2)

[repost] trigger update time

From: Rory Campbell-Lange <rory(at)campbell-lange(dot)net>
To: Postgresql Novice List <pgsql-novice(at)postgresql(dot)org>
Subject: [repost] trigger update time
Date: 2002-06-19 08:36:34
Message-ID: 20020619083634.GB7752@campbell-lange.net (view raw or flat)
Thread:
Lists: 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(at)campbell-lange(dot)net>
<www.campbell-lange.net>

Responses

pgsql-novice by date

Next:From: Ron JohnsonDate: 2002-06-19 10:35:38
Subject: Re: Which indexes to drop
Previous:From: John TaylorDate: 2002-06-19 08:24:56
Subject: Re: Which indexes to drop

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group