Run Code  | API  | Code Wall  | Users  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Postgres Trigger


            
                
            
 run  | edit  | history  | help 0

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 , 4 days ago




Please log in to post a comment.