Re: Modification Dates

From: Sven Schwyn <zeug(at)bluewin(dot)ch>
To: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Modification Dates
Date: 2003-09-29 12:25:34
Message-ID: 0630A275-F278-11D7-BD02-00039398CFBA@bluewin.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Nigel

> I suspect you're misunderstanding something about triggers, an on
> update
> trigger setting a such a field to the current timestamp shouldn't be
> causing a
> second update. You're actually doing an update statement within the
> trigger I
> presume? That's not the way, just set NEW.modified to the value you
> want,
> eg. the current timestamp.

I'm doing it this way but I've read somewhere that this causes a second
UPDATE. If that's not the case, the better!

However, I seem to be missing something else. All my tables contain a
column...

modified TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()

The following function exists...

CREATE FUNCTION touch() RETURNS OPAQUE AS 'BEGIN new.modified = NOW();
RETURN ne
w; END;' LANGUAGE 'plpgsql';

And all tables have the following trigger defined...

CREATE TRIGGER _modified AFTER UPDATE ON any_table FOR EACH ROW EXECUTE
PROCEDURE
touch();

All this returned no errors. I do get a notice though:
NOTICE: CreateTrigger: changing return type of function touch() from
OPAQUE to TRIGGER

I had the impression that now the modified-column should be set to the
NOW() whenever an UPDATE is made on the row. That's not the case, the
value remains unchanged. What's wrong with this?

Your help is greatly apprechiated! -sven

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message btober 2003-09-29 12:35:55 Where are user-defined types stored/viewed
Previous Message Hannu Krosing 2003-09-29 12:23:26 Re: ADD FOREIGN KEY (was Re: [GENERAL] 7.4Beta)