Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a table "Documents"(id serial PK, date timestamp, name varchar, description varchar);
And another table "News"(id serial PK, date timestamp, details varchar).
*In column News.details will be the data from column Documents.description.

I would like to create a function that:
When I update the row in Documents, the row in News will be updated too.
The function uses an After Trigger.

So far I managed to test the following function, it returns no errors, but it doesn`t update the row in News:

create function update_news()
returns trigger as
$$
begin
if (TG_OP = 'UPDATE') then
	update News  
	set details = NEW.description
	where details = OLD.description;
return NEW;
	end if;	
end;
$$
language plpgsql;


The trigger:
create trigger trig_news
after update on Documents for each row execute procedure update_news();


I am working with PostgreSQL.
I would like to ask if anyone can help, or share some ideas, please.

Thank you.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900