| From: | Christophe Labouisse <labouiss(at)cybercable(dot)fr> | 
|---|---|
| To: | pgsql-sql(at)postgreSQL(dot)org, Tulassay Zsolt <zsolt(at)tek(dot)bke(dot)hu> | 
| Subject: | Re: [SQL] auto datetime update on UPDATE? | 
| Date: | 1999-10-31 19:52:38 | 
| Message-ID: | m2n1szz4s9.fsf@localhost.localdomain | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-sql | 
Tulassay Zsolt <zsolt(at)tek(dot)bke(dot)hu> writes:
> Hi,
> 
> i have set up a table, where two fields (creation_dt and modification_dt)
> always get the actual date/time by default when doing an INSERT.
> my question is, how is it possible to let the field modification_dt
> change when doing an UPDATE?
> Is there a way to solve it in SQL?
To do this I use a trigger in plpgsql :
create function liens_maj_fun () returns opaque as '
begin
        new.liens_maj := ''now'';
        return new;
end;
' language 'plpgsql';
create trigger liens_maj_trig before update or insert
    on liens for each row execute procedure liens_maj_fun();
Since it uses plpgsql don't forget to add it when you create your
base:
CREATE FUNCTION plpgsql_call_handler()
   RETURNS opaque
   AS '/usr/local/pgsql/lib/plpgsql.so'
   LANGUAGE 'c';
CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
   HANDLER plpgsql_call_handler
   LANCOMPILER 'PL/pgSQL';
-- 
christophe(dot)labouisse(at)dial(dot)oleane(dot)com
Le cinéma en Lumière : http://www.lumiere.org/
Vote en cours pour la création du forum fr.rec.arts.sf.starwars
pour en savoir plus : <news:38146a03(dot)373985713(at)news(dot)mp-poissy(dot)ac-versailles(dot)fr>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Baris Ulu | 1999-11-01 07:04:53 | Rule plan string too big is overcome, but... | 
| Previous Message | Tulassay Zsolt | 1999-10-31 15:54:50 | auto datetime update on UPDATE? |