automatically updated an attribute with the current time

From: "Mark Bleeker" <mark(at)trilab(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: automatically updated an attribute with the current time
Date: 2002-01-22 11:02:43
Message-ID: NNEMIIOJEJFICLJOAEAKAEBBCFAA.mark@trilab.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello,

I am trying to automatically update an attribute with the current time.

The attribute is a modify-attribute and holds the last modification time of
each row in the table "contacts". If a row is updated the modify-value of
the attribute, should be changed with the current time.

I have tried something myself. I've tried to add a trigger, which calls a
function. Here is what I have tried:

CREATE FUNCTION update_function (int4)
RETURNS int4 (<-- I don't want any return values, I don't see why this is
necessary)
AS 'update contact SET modify = (timestamp(now())) where name = $1;
select id from contact where id = $1;' (<-- I’ve read the an function should
end in an select because of the return value)
LANGUAGE 'SQL';

CREATE TRIGGER update_trigger
AFTER UPDATE ON contacts FOR EACH ROW
EXECUTE PROCEDURE update_function ('id') (<-- I use the id to identify the
row.. I’m not sure if this is necessary)

Unfortunately what I have tried doesn't work. I first insert the function
and after that I insert the trigger. The trigger complains about the
function not existing. When I try to create a function/trigger without input
parameters I get complains the result should be opaque.

I hope someone can help me with this problem. I am new to functions and
triggers. If someone tells me what I am doing wrong, it will be greatly
appreciated.

Thanks in advance.

Mark Bleeker

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Raphael Bauduin 2002-01-22 11:46:01 automated pg_dump
Previous Message Oliver Elphick 2002-01-21 15:20:19 Re: Declaring constants in PG/PLSQL