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 1pSkC2-0001dp-7b for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 19:45:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSkC1-0004XO-24 for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 19:45:21 +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 1pSkC0-0004XF-NT for pgsql-general@lists.postgresql.org; Thu, 16 Feb 2023 19:45:20 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSkBy-0004dy-Cb for pgsql-general@postgresql.org; Thu, 16 Feb 2023 19:45:20 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 665345C013C; Thu, 16 Feb 2023 14:45:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 16 Feb 2023 14:45:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc: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=fm3; t=1676576717; x= 1676663117; bh=Cbms6goZALsqEvcNYLIBr94HicSXuI3VqYgpPZRPnRw=; b=p pplENFfj0Z/luCbRB9YVoOJZIvkqD+AKOwG4bkJ9qu3dJS+YAgixzMoUcZlbZhaH d3MVb948gm0gt3rUA5ZDVs/OJsdWNm2JaDMRCcomD1MQ/NpYOyQNNXBYBHAXKgqO PBDRZU5zUBRUUvWPHpkeBUQqZGjRUuQbQgdqnuXOKcfS2TlkJOJ4Y7XLTPhpvz2O aoTi/f2OHBxXN4g9+swU3vlqFhVe8l+iSCp585ea8JJwoSWpWWM2r72AFEouBgVW Y2zyNzh4fYIOSFAUBiXg3ZEUk9OJ36XshwU1TngM/Sd8hZcoxVrp03hBs8w9GIwf N95BkBBITT4izlm3bjzVQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm1; t=1676576717; x= 1676663117; bh=Cbms6goZALsqEvcNYLIBr94HicSXuI3VqYgpPZRPnRw=; b=c wODVrJLVG81a6HuVLwtZ9MQ6Xbu+j8AWTBixd/q8ZA/spz4uZeaLv0oZ1qxslfFi msCk489/WtSiTEEpxpxLNpwoPaxDiEMis2s45oY9tG/3fsvKh5MxOF0OC8n4aKu4 0uZvLSHikffK2qrLM59LmL52SfLy4VPIQTW/7+wbpdLpA/TaBjQDY+Pn5xG1Ace8 bq60foGZWgTQlJYAJ9H/YfVIMk9UW96JcNrKAf35Q5/wGpUPKiZpvATbvDntGPI1 jXEtXI/bQmzAEss4W+bNIfMTyzfWoo5pg6vcgINGz746EEPWe0ogXrC/bedahtqg +3wSBAGlQWY+98UEUh9Vw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudeijedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttdefjeenucfhrhhomheptegu rhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhmqeenucggtffrrghtthgvrhhnpeehudfgtefhtedtheeiveetueektdejvdfhveek gfdufeegveetuddvuedvgeeggeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Feb 2023 14:45:16 -0500 (EST) Message-ID: Date: Thu, 16 Feb 2023 11:45:16 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: DELETE trigger, direct or indirect? Content-Language: en-US To: Dominique Devienne Cc: "David G. Johnston" , pgsql-general@postgresql.org References: 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 2/16/23 10:28, Dominique Devienne wrote: > On Thu, Feb 16, 2023 at 6:51 PM Adrian Klaver > wrote: > > You have two tables with list in their name, so are rows deleted from > both. Just to be clear enity_list should actually be entity_list? > > Also how are entity and enity_list related? > > > I have to confess that your questions surprise me a bit. > I thought the model was pretty clear from the SQL. > We have two entities, Foo (my entity table), and another Bar (my > entity_list table), > with Bar reference 0 or more Foos, recording which ones it references in > an association table. > > Are the values for the name field in entity and enity(entity)_list the > same for a given entity? > > > The name of Foo and Bar are completely independent. > > > transfering the old entity name to it thanks to an UPDATE on > > entity_name, thus preserving the old name. > > How? > Again how would you determine where the action started? > > > Deleting a Foo cascades to the _member assoc-table. > If the cascade is SET NULL, then I can have an UPDATE TRIGGER on _member. > I no longer care where the action started. What happens if an entity_list value is deleted? Are you going to replicate the above for it to? If so something like what Brad White suggested would seem to simpler. Or, create a history table where rows deleted from entity_list_member are moved to. > > > Then an INSERT trigger on entity could locate any (indexed) > "stashed" > > entity names in that extra non-FK column in entity_list_member, > > How would it locate it if  the name that defined the > FK(entity(name)) was NULL? > > > In the extra non-FK column I mentioned explicitly, in the _member > assoc-table. -- Adrian Klaver adrian.klaver@aklaver.com