Re: automatic time/user stamp - rule or trigger?

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
Cc: Neal Lindsay <neal(dot)lindsay(at)peaofohio(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: automatic time/user stamp - rule or trigger?
Date: 2003-02-05 19:01:43
Message-ID: 3E415F97.62A6E585@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-02-05 19:07:01 Re: design question: status table+log table, indexes, triggers
Previous Message george young 2003-02-05 18:51:37 design question: status table+log table, indexes, triggers