I have two tables A and B. A has the following columns :
a_name, a_num, a_addr. B also has these columns.
Whenever I insert a record in A, I want that record to be inserted in B as well by the use of a trigger.
CREATE OR REPLACE FUNCTION trigger()
RETURNS trigger AS
$BODY$
begin
if tg_op='INSERT' then
insert into b values (new.a_name ,new.a_num ,new.a_addr);
return new;
end if;
return null;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
---------------------------
CREATE TRIGGER trigger_a
AFTER INSERT OR UPDATE
ON a
FOR EACH ROW
EXECUTE PROCEDURE trigger();
ERROR: syntax error at or near "begin" LINE 10: begin