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

Re: Triggers and Functions

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Triggers and Functions
Date: 2006-11-24 12:45:41
Message-ID: 20061124124540.GA12024@a-kretschmer.de (view raw or flat)
Thread:
Lists: pgsql-novice
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
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47215,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

In response to

Responses

pgsql-novice by date

Next:From: Brandon AikenDate: 2006-11-24 16:35:54
Subject: Re: Data (Table) Structure Question
Previous:From: Tom AllisonDate: 2006-11-24 12:25:16
Subject: Triggers and Functions

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