Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1puZzC-0000Eb-Mj for pgsql-general@arkaria.postgresql.org; Thu, 04 May 2023 14:31:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1puZz9-0005m5-N7 for pgsql-general@arkaria.postgresql.org; Thu, 04 May 2023 14:31:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1puZz8-0005lw-9I for pgsql-general@lists.postgresql.org; Thu, 04 May 2023 14:31:07 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1puZz3-000Y9V-J0 for pgsql-general@lists.postgresql.org; Thu, 04 May 2023 14:31:05 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 4829532005BC for ; Thu, 4 May 2023 10:30:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 04 May 2023 10:30:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1683210657; x=1683297057; bh=fuvMIa1KaGVVuhmZ+ELbiCgx0BN73o/uF9y LQqBSc3k=; b=ioWJVNbT5cannzBp6qP10sVC66jHyKtYJelDqV9UmGmP/npbFDz GqNt46Q7xM8nwnly19rnr2gnyKGqZRViYtBiXs2c1j54yE1TxfLOtiWABoonTmRR pi344kPu24LXZqrzx938BQW1D22aPhLvdki/jiNgbk1jvUULquB6HHxLqG3FeqEB cK4ba5AlGsBItlz4neK7s8xLA1HlDVO3DCrWfuzhHDO1uE3lmg/2HBQ8DC5t8mIs 2p3bYJFB5CSmaNX6T6rtUm8s1x8DBbiM2tKkCUJbuUadHB4z3VdfTpoMGgPLrKtc YqfWSWHChiYSWyiiObnyxMckFSRNQ5nDjfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1683210657; x= 1683297057; bh=fuvMIa1KaGVVuhmZ+ELbiCgx0BN73o/uF9yLQqBSc3k=; b=L PdKEs5kR371a+7cfEYNEL+GVl8JpApBAGSK3YknOxMkGKLfs7ceePMy9UFmpVn9A obl2ngPARaQRCEMfRS9Px+7riW96dF+UMer1AZl5VQw8aBsxpgAr0HhFaOA9Sf1I 6PuyReXbjon7YR6RnSOe5U/ak7plbDlfswzxKEHqNhvn3ftEIIiRDkf3XQeZrsQt CZcEpeg5EBd0L3QkpQvw7FGUIocDiq84XuTqxXldEQiOSQIzE6NneGbaiaHO0k0l qTumcNdRlclLRhaIgdcGZB0k/EOzGOBxRiH8iD8YynV7u48F+R0yITCjNIWm9oS2 EG6erUgbtnEU4WmHJD5sA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeftddgjeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepleekgeejhf ekteehfeduveetheeivdduheekudelteefvdffueehtddvgedtfeefnecuffhomhgrihhn pehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgt ohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 4 May 2023 10:30:56 -0400 (EDT) Message-ID: Date: Thu, 4 May 2023 07:30:56 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: Trigger questions To: pgsql-general@lists.postgresql.org References: <1215915755.69415.1683208156758@connect.xfinity.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/4/23 07:03, Justin wrote: > > > On Thu, May 4, 2023 at 9:49 AM DAVID ROTH > wrote: > > __ > 1) Can I create a trigger on a view? > 2) Do triggers cascade? > > Say I have an insert trigger on a table. > And, I have an insert trigger on a view that references this table > If I do an insert on the view, will both triggers fire? > > > Can not have triggers on Views,  Views use  RULES  which are DO INSTEAD. > https://www.postgresql.org/docs/current/rules.html > That is wrong. See https://www.postgresql.org/docs/current/sql-createtrigger.html The following table summarizes which types of triggers may be used on tables, views, and foreign tables: > > Yes if you have an INSERT/UPDATE/DELETE rule on a view  that inserts > into a table then that table's triggers will be executed. > > Please note RULES should  be avoided beyond the use case for VIEWS. > RULES are executed very early in the query tree; it is not > trivial to write rules on Tables. > > Thanks -- Adrian Klaver adrian.klaver@aklaver.com