Re: [NOVICE] trigger to access only the last transaction
От | avpro avpro |
---|---|
Тема | Re: [NOVICE] trigger to access only the last transaction |
Дата | |
Msg-id | CAAQdDnm3gWVxHCu+B0ss5P5XmtqVfJ-wMnDM_Sz1wJ5jZxXOhQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: [NOVICE] trigger to access only the last transaction (Marcos Almeida Azevedo <marcos.al.azevedo@gmail.com>) |
Ответы |
Re: [NOVICE] trigger to access only the last transaction
|
Список | pgsql-sql |
Sorry I forgot to mention: last insert could have multiple rows inserted and I would like to access all of them, not necessarily only the last one. That's my problem. Or I misunderstand the "last entry".
Thank you.
On 9 Mar 2015 08:29, "Marcos Almeida Azevedo" <marcos.al.azevedo@gmail.com> wrote:
On Mon, Mar 9, 2015 at 6:01 AM, avpro avpro <avprowebeden@gmail.com> wrote:manualdueatidtask,table1hi all,i have two tables with several columns:
idtaskhistory
performedat...
idtaskandtable2.....i created a trigger that does the following:
CREATE TRIGGER del1
AFTER INSERT
ON table1
FOR EACH ROW
EXECUTE PROCEDURE taskdel;taskdel:
CREATE OR REPLACE FUNCTION taskdel()
RETURNS trigger AS
$BODY$begin
update table2
SET
manualdueat = null,
FROM table1,
where table1.idtask = table2.idtask;
return new;
END$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION taskdel()
OWNER TO user1;my idea was to have the info from column "manualdueat" deleted after the table1 has been updated. the problem i face is that all columns from table2 will be deleted, not only my last entry where the insert has been done (I was thinking that table1.idtask = table2.idtask will work, but isn't); my question to you would be how to access only the last insert id in table1 and make this trigger working. or do you have another walk arround?How about querying and order by primary key descending and get the first one?
I'm using psql 9.4 on a windows systemthank you for your ideas,John
--Marcos | I love PHP, Linux, and Java
В списке pgsql-sql по дате отправления: