From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: Jan Wieck <JanWieck@Yahoo.com>
Cc: Neal Lindsay <neal.lindsay@peaofohio.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: automatic time/user stamp - rule or trigger?
Date: Fri, 7 Feb 2003 10:00:29 -0200 (GMT+2)
Message-ID: <Pine.LNX.4.44.0302070959510.7803-100000@matrix.gatewaynet.com> (raw)
In-Reply-To: <3E415F97.62A6E585@Yahoo.com>
On Wed, 5 Feb 2003, Jan Wieck wrote:
> Achilleus Mantzios wrote:
> >
> > On Wed, 5 Feb 2003, Neal Lindsay wrote:
> >
> > > I have a table that I want to keep track of the user who last modified
> > > it and the timestamp of the modification. Should I use a trigger or a rule?
> > >
> > > CREATE TABLE stampedtable (
> > > stampedtableid SERIAL PRIMARY KEY,
> > > updatestamp timestamp NOT NULL DEFAULT now(),
> > > updateuser name NOT NULL DEFAULT current_user,
> > > sometext text
> > > );
> > >
> > > I suspect that I want a rule, but all the examples in the documentation
> > > seem to update a separate table and not override (or add) the
> > > insert/update to the timestamp and name columns.
> >
> > You may want to use rules if you need rewriting.
> > What you actually need is some sort of driver to a specific table.
> > You could create a view to that table (to hide the accounting columns),
> > and then create rules on that view that do the job as you wish.
>
> I'm sure you want to use a BEFORE INSERT OR UPDATE trigger that modifies
> NEW.updatestamp in place just before the row get's written.
>
> A rule will not work here because rules cannot cause the same action on
> the same table they are called for.
Thats why the view comes in place.
>
>
> Jan
>
> --
> #======================================================================#
> # It's easier to get forgiveness for being wrong than for being right. #
> # Let's break this rule - forgive me. #
> #================================================== JanWieck@Yahoo.com #
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
==================================================================
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
Nikis 4, Glyfada
Athens 16610
Greece
tel: +30-10-8981112
fax: +30-10-8981877
email: achill@matrix.gatewaynet.com
mantzios@softlab.ece.ntua.gr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: achill@matrix.gatewaynet.com, JanWieck@Yahoo.com, neal.lindsay@peaofohio.com
Subject: Re: automatic time/user stamp - rule or trigger?
In-Reply-To: <Pine.LNX.4.44.0302070959510.7803-100000@matrix.gatewaynet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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