Trigger function problem

From: Liglio Cavalcante <liglio(at)pobox(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Trigger function problem
Date: 2017-10-04 19:36:32
Message-ID: 1507145792892-0.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I am trying to migrate data from a master table to her partitions. I am
using an update trigger to delete and insert into the master table, and so
an insert trigger on the master table redirects the inserted registers to
the respective parrtition table. The problem is that the update trigger is
not deleting the registers from the master table. I am using postgresql 9.5.

CREATE OR REPLACE FUNCTION tb_master_update_trigger()
RETURNS TRIGGER AS $$
BEGIN
DELETE FROM tb_master WHERE OLD.id_master = id_master ;
INSERT INTO tb_master VALUES (NEW.*);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER update_tb_master_trigger
BEFORE UPDATE ON tb_master
FOR EACH ROW EXECUTE PROCEDURE tb_master_update_trigger();

UPDATE tb_master SET id_master = id_master ;

--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html

Browse pgsql-general by date

  From Date Subject
Next Message Frank Millman 2017-10-05 05:01:01 Re: a JOIN to a VIEW seems slow
Previous Message Alban Hertroys 2017-10-04 19:19:14 Re: a JOIN to a VIEW seems slow