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 1oJSjm-0002jF-Eg for pgsql-general@arkaria.postgresql.org; Thu, 04 Aug 2022 04:45:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJSjk-0004Yb-5u for pgsql-general@arkaria.postgresql.org; Thu, 04 Aug 2022 04:45:32 +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 1oJSji-0004YR-Ql for pgsql-general@lists.postgresql.org; Thu, 04 Aug 2022 04:45:31 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJSje-0004ZE-Ci for pgsql-general@lists.postgresql.org; Thu, 04 Aug 2022 04:45:30 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D983D5C00E3; Thu, 4 Aug 2022 00:45:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 04 Aug 2022 00:45:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding: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=1659588323; x= 1659674723; bh=PIqA8pQtmkQph+ft4S0OsgP2ujZ0I4MSIZOBryqLyco=; b=H ltf6fWO7mdHHS1mzegzq/sEQ0HoxcCqOgAU0mmbMuqSBwWQv7v+g5J1vGyQs4UML +uLrjrmIjs1LyLs5aHAjGcdHbtna2d1/nVwB62p5hqZi4iSThZYj6it795FSS13t zVWr0v9Eum8PeaPsqO3nvlOw/L7iwkrtd8077f3mlcQBFogZnlY22c2VZR59bsUS g03CCO0brvqNNVMESbeRzaguYh4aDYN7dL+MysqvZ/EwmPEtCqymKltnKwemXeWg 55W9ZEeGF/WOfwvBq8DbsLyd/vpe2zsZ1IgSZmE4L48oycSSKY0M1LjRQqOrzLCv 0sUT0v7b/trforsjVAQDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1659588323; x=1659674723; bh=P IqA8pQtmkQph+ft4S0OsgP2ujZ0I4MSIZOBryqLyco=; b=czj1AcUcyFgL0dpFp g0doP6i9ohYQoBhG9LPZPb9qgK4TlubuO7L4p7s1NfkekvFd1OLLEFz3A6Yel/LB BaujXnQhAsUEhw7PQTjDcHbw4bG8Mcqp45VM/GVR63ZHnjrsX+10p/EfVSljRXkC NVHfLTwYoM+Lq5yfZplbhq6D8CX+SjgtvaT7xHA6fgzrruUAtkEK0q8w3YyJtFh9 K3d/y/iDM7ooAEA/uB9qs1CewzPPWUyKpHrNu6XLZo70IZAN4fJJqFGrJtbpWBKw RzthPWxqyBcuunCpkQFOsX+RCpR2mgZvW4utaPYTl9uXrzxohtk7K9kj6LfjZyXw nI3GQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvddvkedgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeffudehtddugefgkeevudffheevvefhfeettdfhveei vdfgieeghfeiueeggffggeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 4 Aug 2022 00:45:23 -0400 (EDT) Message-ID: <05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com> Date: Wed, 3 Aug 2022 21:45:22 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: Purpose of DEFERRABLE _and_ INITIALLY DEFERRED foreign key constraint checking? Content-Language: en-US To: Ron , "pgsql-generallists.postgresql.org" References: <0317c0c5-a7e5-9073-01b9-80391491108b@aklaver.com> From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/3/22 18:13, Ron wrote: > On 8/3/22 20:02, Adrian Klaver wrote: >> On 8/3/22 17:30, Ron wrote: >>> AWS RDS Postgresql 12.10 > > And https://www.postgresql.org/docs/12/sql-set-constraints.html seems to > say that SET CONSTRAINTS can make DEFERRABLE FKs temporarily not > deferrable. > > What's the point? The way I think of it is: 1) CONSTRAINTS are something that is supposed to constrain an action. 2) Setting DEFERRABLE is a cheat code to push 1) out to the end of a transaction by using INITIALLY DEFERRED. 3) If the constraint was created/altered to DEFERRABLE INITIALLY DEFERRED the SET CONSTRAINTS IMMEDIATE unsets the cheat code in a given transaction. Maybe for most cases you want the check done at the end of the transaction, but in a specific case you need that check to happen before another statement occurs prior to the end of the transaction. -- Adrian Klaver adrian.klaver@aklaver.com