From: | "Jules Alberts" <julesa(at)arbodienst-limburg(dot)nl> |
---|---|
To: | <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: automatically updated an attribute with the current time |
Date: | 2002-01-23 11:27:38 |
Message-ID: | 200201231136.g0NBa2M2006052@artemis.cuci.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On 22 Jan 2002 at 12:02, Mark Bleeker wrote:
> Hello,
>
> I am trying to automatically update an attribute with the current time.
<snip>
from one newbie to another :)
i just figured it out yesterday:
-------------------------------------------------------
-- this is a templatetable, other tables inherit their
-- audit columns from it
drop table au_col;
create table au_col (
mut_id varchar(100) not null default current_user,
mut_timestamp timestamp not null default CURRENT_TIMESTAMP
);
-- function to change the values
drop function au_col();
create function au_col()
returns opaque
as 'begin
old.mut_id = current_user;
old.mut_timestamp = CURRENT_TIMESTAMP;
return old;
end;'
language 'plpgsql';
-- trigger to call the funtcion
drop trigger au_col on au_col;
create trigger au_col
before update or delete -- create is covered by defaults
on au_col
for each row
execute procedure au_col();
-------------------------------------------------------
HTH, HAND
--
Jules Alberts
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Bleeker | 2002-01-23 13:43:37 | Re: automatically updated an attribute with the current time |
Previous Message | Mark Hesketh | 2002-01-23 05:12:48 | Re: Declaring constants in PG/PLSQL |