pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feeddefaults on updates
2+ messages / 2 participants
[nested] [flat]
* defaults on updates
@ 2003-11-01 13:49 Martin Marques <martin@bugs.unl.edu.ar>
2003-11-01 15:24 ` Re: defaults on updates Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Martin Marques @ 2003-11-01 13:49 UTC (permalink / raw)
To: pgsql-sql
Hi,
I'm trying to make some sort of function, rule, trigger, or what ever that
would be capable of modifing my table on an update.
Basically, I have 5 fields, one being a PK (SERIAL), 3 with information, and
the last one a timestamp field that will show the last time the register was
modified (tmodif which has a DEFAULT CURRENT_TIMESTAMP).
Now, eveytime someone modifys any, or all of the 3 information fields, I want
the tmodif field of that register to be set to now(). I tried with rules, but
just didn't work (obviously, and not so), even with INSTEAD.
The only way I see of doing it is through a view/rule, but I would leave that
as the last resource.
Any ideas?
--
10:43:01 up 10 days, 18:05, 4 users, load average: 0.95, 0.44, 0.35
-----------------------------------------------------------------
Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar'
Centro de Telematica | DBA, Programador, Administrador
Universidad Nacional
del Litoral
-----------------------------------------------------------------
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: defaults on updates
2003-11-01 13:49 defaults on updates Martin Marques <martin@bugs.unl.edu.ar>
@ 2003-11-01 15:24 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2003-11-01 15:24 UTC (permalink / raw)
To: Martin Marques <martin@bugs.unl.edu.ar>; +Cc: pgsql-sql
Martin Marques <martin@bugs.unl.edu.ar> writes:
> Basically, I have 5 fields, one being a PK (SERIAL), 3 with information, and
> the last one a timestamp field that will show the last time the register was
> modified (tmodif which has a DEFAULT CURRENT_TIMESTAMP).
> Now, eveytime someone modifys any, or all of the 3 information fields,
> I want the tmodif field of that register to be set to now().
This is trivial to do with a trigger --- you just need something like
NEW.lastmod := now();
RETURN NEW;
There's a complete example at the bottom of this page:
http://developer.postgresql.org/docs/postgres/plpgsql-trigger.html
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-11-01 15:24 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-11-01 13:49 defaults on updates Martin Marques <martin@bugs.unl.edu.ar>
2003-11-01 15:24 ` Tom Lane <tgl@sss.pgh.pa.us>
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