Re: Triggers and Functions - Mailing list pgsql-novice

From Tom Allison
Subject Re: Triggers and Functions
Date
Msg-id 456720FA.8070300@tacocat.net
Whole thread Raw
In response to Re: Triggers and Functions  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-novice
A. Kretschmer wrote:
> am  Fri, dem 24.11.2006, um  7:25:16 -0500 mailte Tom Allison folgendes:
>> I would like to create a function/trigger which will update a timestamp on
>> table A when an UPDATE is executed against table B
>> CREATE FUNCTION update_token(bigint) RETURNS void AS '
>>   UPDATE tokens SET last_seen = now()
>>   WHERE token_idx = $1 and last_seen < now();
>> ' LANGUAGE SQL
>>
>>
>> CREATE TRIGGER touch_token AFTER UPDATE ON user_token FOR EACH ROW
>> EXECUTE PROCEDURE update_token(token_idx)
>>
>>
>> But it doesn't seem to change the filed 'last_seen' on the tokens table...
>
> I think, you should better create a RULE like this:
>
> create rule update_rule as on update to user_token do also update tokens set last_seen = now() where token_idx =
NEW.token_idx;
>
> Andreas


This works perfectly.

pgsql-novice by date:

Previous
From: "Brandon Aiken"
Date:
Subject: Re: Data (Table) Structure Question
Next
From: Richard Broersma Jr
Date:
Subject: Re: Data (Table) Structure Question