Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9Dme-0007Lc-FF for pgsql-general@arkaria.postgresql.org; Thu, 19 Apr 2018 17:55:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9Dmc-0001yT-IL for pgsql-general@arkaria.postgresql.org; Thu, 19 Apr 2018 17:55:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9Dmc-0001yJ-AF for pgsql-general@lists.postgresql.org; Thu, 19 Apr 2018 17:55:46 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9DmT-00072a-Jn for pgsql-general@postgresql.org; Thu, 19 Apr 2018 17:55:44 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id D1853C693550 for ; Thu, 19 Apr 2018 10:55:34 -0700 (MST) Date: Thu, 19 Apr 2018 10:55:34 -0700 (MST) From: PegoraroF10 To: pgsql-general@postgresql.org Message-ID: <1524160534707-0.post@n3.nabble.com> Subject: Problem with trigger makes Detail record be invalid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I=C2=B4m using Postgres 10 on ubuntu. suppose a simple Master/Detail structure like this: create table Master(ID integer primary key, name text); create table Detail(ID integer primary key, Master_ID Integer, OtherInfo text); alter table Detail add constraint FKMasterDetail foreign key (Master_ID) references Master(ID) on update cascade on delete cascade; Then insert some records on it: insert into Master(ID, Name) values(1,'First'), values(2,'Second'); insert into Detail(ID, Master_ID, OtherInfo) values(1,1,'Detail Information'), (2,2,'Detail Information2'); Then, if I delete on Master will delete on detail too. Fine. delete from Master where ID=3D1; But now, suppose I have a complex trigger before update or delete that runs on Detail table. create function DoAComplexJobOnDetail() returns trigger as $$ begin -- Do lots of things then Return new; --This is the error, because I=C2=B4m returning new even for delete; end;$$ language plpgsql; create trigger DetailDoAComplexJob before update or delete on Detail for each row execute procedure DoAComplexJobOnDetail(); Then try to delete the other Master record. It will be deleted on Master bu= t Detail record doesn=C2=B4t and will obviously become invalid because the fo= reign key. delete from Master where ID=3D2; select * from Master; --will show no records. select * from Detail; --will show one record pointing to Master_ID=3D2, tha= t doesn=C2=B4t exist anymore. Is this a bug or it=C2=B4s mine responsability to check that trigger result= ? If that trigger responds incorrectly I think that no information could be executed. -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.ht= ml