pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
auto datetime update on UPDATE?
4+ messages / 3 participants
[nested] [flat]

* auto datetime update on UPDATE?
@ 1999-10-31 15:45  Tulassay Zsolt <zsolt@tek.bke.hu>
  0 siblings, 0 replies; 4+ messages in thread

From: Tulassay Zsolt @ 1999-10-31 15:45 UTC (permalink / raw)
  To: pgsql-sql


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?

(actually i found something in the mailing list archive,
where the sender solves the problem by creating a trigger
and a C function, but i would really apppreciate if there was
a solution in SQL only.
anyway, that solution is at
http://www.PostgreSQL.ORG/mhonarc/pgsql-sql/1998-06/msg00056.html )

Zsolt Tulassay

ps i'm not on the mailing list so please send a copy to my address
   as well. thanks





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* auto datetime update on UPDATE?
@ 1999-10-31 15:54  Tulassay Zsolt <zsolt@tek.bke.hu>
  0 siblings, 2 replies; 4+ messages in thread

From: Tulassay Zsolt @ 1999-10-31 15:54 UTC (permalink / raw)
  To: pgsql-sql


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?

(actually i found something in the mailing list archive,
where the sender solves the problem by creating a trigger
and a C function, but i would really apppreciate if there was
a solution in SQL only.
anyway, that solution is at
http://www.PostgreSQL.ORG/mhonarc/pgsql-sql/1998-06/msg00056.html )

Zsolt Tulassay

ps i'm not on the mailing list so please send a copy to my address
   as well. thanks






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] auto datetime update on UPDATE?
@ 1999-10-31 19:52  Christophe Labouisse <labouiss@cybercable.fr>
  parent: Tulassay Zsolt <zsolt@tek.bke.hu>
  1 sibling, 0 replies; 4+ messages in thread

From: Christophe Labouisse @ 1999-10-31 19:52 UTC (permalink / raw)
  To: pgsql-sql@postgreSQL.org, Tulassay Zsolt <zsolt@tek.bke.hu>

Tulassay Zsolt <zsolt@tek.bke.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.labouisse@dial.oleane.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.373985713@news.mp-poissy.ac-versailles.fr>



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] auto datetime update on UPDATE?
@ 1999-11-01 14:46  Darrin Crook <crook@nexus.as.utexas.edu>
  parent: Tulassay Zsolt <zsolt@tek.bke.hu>
  1 sibling, 0 replies; 4+ messages in thread

From: Darrin Crook @ 1999-11-01 14:46 UTC (permalink / raw)
  To: Tulassay Zsolt <zsolt@tek.bke.hu>; +Cc: pgsql-sql


	This is wat I have done to solve the problem.

UPDATE table SET modification_dt = datetime('now'::abstime);

You can update any other field at the same time. This enters the date-time
stamp into the filed. And you can use this format for INSET INTO also.

I hope this helps.

Darrin Crook				crook@nexus.as.utexas.edu
McDonald Observatory			wk: 915-426-4167
The University of Texas at Austin	hm: 915-426-3652

On Sun, 31 Oct 1999, Tulassay Zsolt wrote:
 
> 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?




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~1999-11-01 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-10-31 15:45 auto datetime update on UPDATE? Tulassay Zsolt <zsolt@tek.bke.hu>
1999-10-31 15:54 auto datetime update on UPDATE? Tulassay Zsolt <zsolt@tek.bke.hu>
1999-10-31 19:52 ` Christophe Labouisse <labouiss@cybercable.fr>
1999-11-01 14:46 ` Darrin Crook <crook@nexus.as.utexas.edu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox