automatically updated an attribute with the current time - Mailing list pgsql-novice

From Mark Bleeker
Subject automatically updated an attribute with the current time
Date
Msg-id NNEMIIOJEJFICLJOAEAKAEBBCFAA.mark@trilab.com
Whole thread Raw
Responses Re: automatically updated an attribute with the current time  ("Jules Alberts" <julesa@arbodienst-limburg.nl>)
List 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


pgsql-novice by date:

Previous
From: Oliver Elphick
Date:
Subject: Re: Declaring constants in PG/PLSQL
Next
From: Raphael Bauduin
Date:
Subject: automated pg_dump