Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMw3y-0007QB-2s for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 15:27:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMw3v-000109-7N for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 15:27:07 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMw3u-0000xV-Re for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 15:27:06 +0000 Received: from post.visena.com ([46.226.10.50]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMw3o-00062s-KN for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 15:27:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=visena.com; s=20141101.wh; h=Content-Type:MIME-Version:Subject:In-Reply-To:Message-ID:To:From:Date; bh=GppstpkKeOVCIpFTjCojqiTv67lwFmHAyc8etFc5L88=; b=CCQNIY6EMfdwMHJTZunH5mmDRLqsEU60Y6CvqjlxYGxMzewZtsMg4Mxr9ImdK71ws8qCoor0bhuX8F7FDUXk0GZGNPiOW+mRczBuDvC8cCVUTEnxPvrTlWT8cikCY4SbOietFrKcoiukymdrRNPSk1wcAZNcSLQRwA9taFEbk6s=; Received: from [10.0.1.10] (helo=tc7-visena.wh.internal.visena.com) by post.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1iMw3l-0003th-PU for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 17:26:59 +0200 Received: from localhost ([127.0.0.1] helo=tc7-visena.wh.internal.visena.com) by tc7-visena.wh.internal.visena.com with esmtp (Exim 4.90_1) (envelope-from ) id 1iMw3l-00046u-Na for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 17:26:57 +0200 Date: Tue, 22 Oct 2019 17:26:57 +0200 (CEST) From: Andreas Joseph Krogh To: pgsql-general@lists.postgresql.org Message-ID: In-Reply-To: <27796c9e-4e3a-72bd-ad69-02733e989ab9@aklaver.com> Subject: Re: Having more than one constraint trigger on a table MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_155_1035002818.1571758017633" X-Mailer: Visena Mail 2.2.150 X-Spam-Score: -1.0 X-Spam-Report: SpamAssasin (score=-1.0, required 5.0 ALL_TRUSTED=-1,HTML_MESSAGE=0.001) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_155_1035002818.1571758017633 Content-Type: multipart/related; boundary="----=_Part_156_790459977.1571758017633" ------=_Part_156_790459977.1571758017633 Content-Type: multipart/alternative; boundary="----=_Part_157_1191874896.1571758017643" ------=_Part_157_1191874896.1571758017643 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 tirsdag 22. oktober 2019 kl. 17:12:59, skrev Adrian Klaver < adrian.klaver@aklaver.com >:=20 [snip] No. When I sort the triggers I get: test=3D# create table trg_str(fld_1 varchar); CREATE TABLE test=3D# insert into trg_str values ('trigger_1_update_fts'), ('trigger_2'), ('trigger_3'), ('trigger_1_check_nocycle'); INSERT 0 4 test=3D# select * from trg_test order by fld_1 ; id | fld_1 ----+------- (0 rows) test=3D# select * from trg_str order by fld_1 ; fld_1 ------------------------- trigger_1_check_nocycle trigger_1_update_fts trigger_2 trigger_3 Is this how you want them to fire as it does not match what you say above?= :=20 (I know they were not declared in that order, but..)=20 Yes, all "trigger_1_*" are the "actuall triggers triggering the logic",=20 trigger_2 and trigger_3 are only there as part of the "make constraint-trig= gers=20 fire only once"-mechanism, in which the function in the first trigger is th= e=20 function performing the actual logic.=20 So, being I want 2 "logical chunks" to happen I have two "trigger_1"-trigge= rs=20 (there is no established terminilogy for this AFAIK), each calling a functi= on=20 performing the logick which is to happen only once (per row).=20 "The first "main" trigger-function is update_company_fts_tf() ... The second "main" trigger-function is company_parent_no_cycle()" It might be easier to understand if sketch out a schematic version of what you are trying to achieve.=20 The point is; I want to functions to be called=20 - update_company_fts_tf()=20 - company_parent_no_cycle()=20 , each only once, as constraint-triggers on the same table. So they are cal= led=20 by the "level 1 triggers" which must fire first.=20 Is it clearer now what I'm trying to achieve?=20 -- Andreas Joseph Krogh ------=_Part_157_1191874896.1571758017643 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 tirsdag 22. oktober 2019 kl. 17:12:59, skrev Adrian Klaver <= ;adrian.klaver@aklaver.com= >:
[sn= ip]
No.
When I sort the triggers I get:

test=3D# create table trg_str(fld_1 varchar);
CREATE TABLE
test=3D# insert into trg_str values ('trigger_1_update_fts'),
('trigger_2'), ('trigger_3'), ('trigger_1_check_nocycle');
INSERT 0 4
test=3D# select * from trg_test order by fld_1 ;
=C2=A0 id | fld_1
----+-------
(0 rows)

test=3D# select * from trg_str order by fld_1 ;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fld_1
-------------------------
=C2=A0 trigger_1_check_nocycle
=C2=A0 trigger_1_update_fts
=C2=A0 trigger_2
=C2=A0 trigger_3

Is this how you want them to fire as it does not match what you say above?:=
=C2= =A0
(I = know they were not declared in that order, but..)
Yes= , all "trigger_1_*" are the "actuall triggers triggering the= logic", trigger_2 and trigger_3 are only there as part of the "m= ake constraint-triggers fire only once"-mechanism, in which the functi= on in the first trigger is the function performing the actual logic.
So,= being I want 2 "logical chunks" to happen I have two "trigg= er_1"-triggers (there is no established terminilogy for this AFAIK), e= ach calling a function performing the logick which is to happen only once (= per row).
=C2= =A0
=C2= =A0
&qu= ot;The first "main" trigger-function is update_company_fts_tf() .= .. The
second "main" trigger-function is company_parent_no_cycle()"=

It might be easier to understand if sketch out a schematic version of
what you are trying to achieve.
=C2=A0
The point is; I want to functions to be called
=C2=A0
- update_company_fts_tf()
- company_parent_no_cycle()
=C2=A0
, each only once, as constraint-triggers on the same table. So they ar= e called by the "level 1 triggers" which must fire first.
=C2=A0
Is it clearer now what I'm trying to achieve?
=C2=A0
">
--
Andreas Joseph Krogh
------=_Part_157_1191874896.1571758017643-- ------=_Part_156_790459977.1571758017633-- ------=_Part_155_1035002818.1571758017633--