drop table if exists table1;
drop table if exists table2;
create table table1( id integer NOT NULL,name character varying);
create table table2(id integer NOT NULL,name character varying);
create or replace function function_copy()
returns trigger language plpgsql as $$
begin
insert into
table2(id,name)
values(new.id,new.name);
return new; {https://rextester.com/jwfk49377};
$$;
create trigger trig_copy
before insert or update on table1
for each row execute procedure function_copy();
insert into table1 (id, name)
values (1, 'John');
insert into table1 (id, name)
values (2, 'John2');
select *
from table1;
select *
from table2;
delete from table1 where id=1;
select *
from table1;
select *
from table2;
drop table if exists table1; drop table if exists table2; create table table1( id integer NOT NULL,name character varying);
create table table2(id integer NOT NULL,name character varying);
create or replace function function_copy() returns trigger language plpgsql as $$ begin insert into table2(id,name) values(new.id,new.name); return new; {https://rextester.com/jwfk49377};
$$;
create trigger trig_copy before insert or update on table1 for each row execute procedure function_copy();
insert into table1 (id, name) values (1, 'John'); insert into table1 (id, name) values (2, 'John2');
select * from table1;
select * from table2;
delete from table1 where id=1; select * from table1; select * from table2;
by Cramdepancramdepan@gmail.com , 3 months agoPlease log in to post a comment.