Re: automatically updated an attribute with the current time - Mailing list pgsql-novice

From Jules Alberts
Subject Re: automatically updated an attribute with the current time
Date
Msg-id 200201231136.g0NBa2M2006052@artemis.cuci.nl
Whole thread Raw
In response to automatically updated an attribute with the current time  ("Mark Bleeker" <mark@trilab.com>)
Responses Re: automatically updated an attribute with the current time  ("Mark Bleeker" <mark@trilab.com>)
List 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

pgsql-novice by date:

Previous
From: Mark Hesketh
Date:
Subject: Re: Declaring constants in PG/PLSQL
Next
From: "Mark Bleeker"
Date:
Subject: Re: automatically updated an attribute with the current time