automatically updated an attribute with the current time
От | Mark Bleeker |
---|---|
Тема | automatically updated an attribute with the current time |
Дата | |
Msg-id | NNEMIIOJEJFICLJOAEAKAEBBCFAA.mark@trilab.com обсуждение исходный текст |
Ответы |
Re: automatically updated an attribute with the current time
|
Список | 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;' (<-- Ive 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.. Im 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 по дате отправления: