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 1pSiPf-0003se-NC for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 17:51:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSiPc-0007w4-Mk for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 17:51:16 +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 1pSiPb-0007qw-1b for pgsql-general@lists.postgresql.org; Thu, 16 Feb 2023 17:51:16 +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 1pSiPT-0003bh-O1 for pgsql-general@postgresql.org; Thu, 16 Feb 2023 17:51:14 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id E856B5C0136; Thu, 16 Feb 2023 12:51:05 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 16 Feb 2023 12:51:05 -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=1676569865; x= 1676656265; bh=0yhxIH1lAoiJggSvjgD/EeM1aWIvnuNa8/dFftNjbW0=; b=p Tlpo5rzpFIPq3DxvB6d9Z+c8QK6LV/rzJ0U5KPHzOxuEvqXrbWV1x49s5T0eOLSB 0qEekfaw0hTs5zI1JrvPn5ZdmWX6yIvI3MG/E1tRUSyCai71Q0rmkyGB1wXZIIv7 uF84TkPLB8M4KzdjmajjKPeyNpM49rkML/UZpjJPRhX045EpIbSmARZogHcUk/FB tloaDGUGandNmBJdiWSOUICvTVZWFlILDOUp5BP2EBfjbCF3qIapArAruB/32XlK oXl+YvpEj96+CxriwAm+mU7GKQ7yAZoK0YhvRMxCR4eWTtdf+hW3gyCM7yBcOdJ3 HiL9PV/pAZyxKJZui0lRg== 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=1676569865; x= 1676656265; bh=0yhxIH1lAoiJggSvjgD/EeM1aWIvnuNa8/dFftNjbW0=; b=H mEihUg5Sb6op5tMcEhe0LC42IrbUbwjohGOkl+D56EEiaHhRTXJJB71qagJwyQ6p U9/ORkAfTD4rlU+HakllTuuQOeYmHJ1jA3iDSn8MmsEtftnrrPzPXyUtdWaeFdcD 0iR9suK+t9dFWYIlvcTk/9JqbmgBbehwkkctXDfDsOUAvB0AkYvrVErek2IxqUDz 8CHVZ3mXLPcRLoJ2Z4PZGK/FKw66UsNESQv2uGkkCEo7AJR61TsAQH5T2qqjOrJR OqMhGHcqHCt5J3z4B2U3LiCKeKimtEDFkcCzykHC6jWgDoUbUKSA2qyPab+IqvNb hhc37JLmnqISFqmY9D5bw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudeijedguddtfecutefuodetggdotefrod 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 12:51:05 -0500 (EST) Message-ID: Date: Thu, 16 Feb 2023 09:51:04 -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 09:17, Dominique Devienne wrote: > That is where I am headed, however it will need more information to > determine whether that makes sense or not. > > > OK, I started writing SET NULL won't help, but I'll back up and try to > give more info, as requested. > Pseudo SQL at this point. > > create table entity (name text primary key, ...); > create table enity_list (name text primary key, ...); > create table entity_list_member( >   list_name text not null references entity_list(name) on delete > cascade on update cascade, >   entity_name text not null references entity(name) on delete cascade > on update cascade >   primary key (list_name, entity_name) > ); > > Above is the current situation. When the entity is deleted, it's > implicitly deleted from all list that mention it. > Referential Integrity 101 I guess. But apparently, it's common enough > for an entity to be deleted and reloaded, > not necessarily in the same transaction, that losing the list(s) > membership on delete is considered "a bug". 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? > > One solution is to not do any reference integrity in the lists. But that > opens the door to garbage in a little too wide I think. > > So on second thought, maybe the SET NULL could be of use. I'd add a > second non-FK column on the member assoc-table, Are the values for the name field in entity and enity(entity)_list the same for a given entity? > 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? > 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? > to retransfer the name back to the primary FK column. > I'd need to adjust the PK to a coalesce(), and ensure the two columns > are mutually exclusive. > Sounds like that might work, no? > -- Adrian Klaver adrian.klaver@aklaver.com