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 1iYAon-0000no-Ud for pgsql-general@arkaria.postgresql.org; Fri, 22 Nov 2019 15:25:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iYAok-0001En-3Q for pgsql-general@arkaria.postgresql.org; Fri, 22 Nov 2019 15:25:54 +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 1iYAoj-0001Ee-PR for pgsql-general@lists.postgresql.org; Fri, 22 Nov 2019 15:25:53 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iYAog-0007Wp-3a for pgsql-general@postgresql.org; Fri, 22 Nov 2019 15:25:52 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id CC8049C5; Fri, 22 Nov 2019 10:25:46 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 22 Nov 2019 10:25:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=i brzO19dasyORFOh3NZB1AnIj8XrXnTy8c3GNufKZC4=; b=kiTct1Rgs3vxDXgPS 0IKE8wjLo/9eB8Ff6qrzEIkEZE2oj0LgWrRtmXfllN6qFYfu6pPEaL7eT1E80Q/U +WaZq83IZ/jYMxEiTGHAXWOeX92Ep5Qik4R4zFT8ZT0aN/b4UwaYEnqaOX4bSTlu bg1Qxl1fEgm/tS3v9DWiJqG30LUHvqs9cjuWlV/RXrHxyZWtI876J5ApwS+ejmrp hXSqzSLKUVk45AUi1iQIx3X6mR0wKAQ8w8Pz8QH8diAH0EfxUJmsWNyX3cGHm+t0 4UDfw9t8iuWagrRw/si8TvpkiqMQTLcaPgm6VrthXhHO6Bv3S4m16cIcO5ZSNQ3l CQb3g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=ibrzO19dasyORFOh3NZB1AnIj8XrXnTy8c3GNufKZ C4=; b=ecIjmyqag7zM1riVUe2s1PmZNikirATTUtJ16fM8u9r6XJl7KGh9CtGyv ba0L755q0Gzoz7bAjSsRPxGdBIxNl5yI9J7i3ZYedq60mMTrwyaCSGK1tGSK/VLZ 1yZtN6VVkzi1Zwxine18sFkTsHUjxC2beCF+c72+BHDQW9ZAb7lzDISyoLjQ7a6m mrIwHxHuskVMlJcxVGZqc5R8ymf6ED3DL4atuiNZ7x9SN9rlHFOeW49iNlACg5dg uTo7BCnYWomYM5G6qqHWWy0MBKGN/KyFMaWMp6GKtJfj3rqS5LlC18CD9KBGoloI AzLO0wwcvW6Ga97w5ZNJr0T9B6Zdg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudehgedgjeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejuddrvddu vddrudeffedruddukeenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklh grvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.133.118]) by mail.messagingengine.com (Postfix) with ESMTPA id A8F9080064; Fri, 22 Nov 2019 10:25:45 -0500 (EST) Subject: Re: Constants in the foreighn key constraints To: aleksey ksenzov , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <85f6184b-cd37-0b7e-9bee-b0d781cead6f@aklaver.com> Date: Fri, 22 Nov 2019 07:25:44 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/22/19 6:32 AM, aleksey ksenzov wrote: > Hi team. > Latest time we faced several issues which wouldn't arise provided we > have possibility to use constants in foreign key constraints. > brief example where it would be helpful: > > table_a > ( id uuid, > parent_id uuid, > is_deleted boolean > ) > having possibility of FK (parent_id, false) to (id, is_deleted) > would disallow setting parent record deleted flag to true if they have > children, or insert record with is_deleted = true parent. Postgres version? Look at triggers, in particular CONSTRAINT triggers: https://www.postgresql.org/docs/12/sql-createtrigger.html > > Regards, > Aliaksei. -- Adrian Klaver adrian.klaver@aklaver.com