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 1nHrqg-0007A8-4d for pgsql-general@arkaria.postgresql.org; Wed, 09 Feb 2022 18:37:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nHrqf-00010a-0y for pgsql-general@arkaria.postgresql.org; Wed, 09 Feb 2022 18:37:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHrqd-00010R-U2 for pgsql-general@lists.postgresql.org; Wed, 09 Feb 2022 18:37:48 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHrqb-0002H0-D1 for pgsql-general@lists.postgresql.org; Wed, 09 Feb 2022 18:37:46 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C2AC45C01B7; Wed, 9 Feb 2022 13:37:44 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 09 Feb 2022 13:37:44 -0500 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; bh=cSRguF78N1OCik GWn13/nwfuhf0+Walfo74p9UeFwBM=; b=S3NBIXXKAU2BwpM02yFN75ORo8Z3v4 AitIWfhZ4+pCOKeiI5eH23vkw2+Dy177kL3s2q9UVE8qowl/as+xNZOIFugYDlid wY3GWkaXsQm18OxcvD4yv8xc4cEjXeL0a2mYQp41qt9DLkF4uLLz3iUppyue2fxh zZVg/JsXjcTqwb/Hji4JGEIend7074JduOdi5g/bF7CHAfwEcJqaN1+ahLvS9zQH auzA6qxOz7U7KvQMmbu7czq3KQjodizHrC3eityIQgFHcXx2cA2kFJ9dh56s8C87 vLEJDGOXK7BquqP4rcM31WMa5l+SwDskDtVNuoeyryuQAxTV/SCFpepA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.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 :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=cSRguF78N1OCikGWn13/nwfuhf0+Walfo74p9UeFwBM=; b=UVWJM74m hckD6KbZSl7Va4Gic6J3Zb+UEjLoMR6alCsGRGXgX3WaAakHsyXiIqY5dRLRCKxh E2gAykKvvq9ekJrII+txygDnh9EyIPSSkk8V29xRc79uKO5dvrh/lNMmNtBAFDrz ltGHvZ9U6LR+tRguNy7P9nx6hDrIovu3Skm85D+7zg2wanpBq3dmRKkmD45O7vmk HSb8rR7tmgMeVPjsrQqWwaRY6TIZTs9UHAtfNHOe3ldKEeQuy5C3Ybv52ewjhpX6 FUDyHbOHvlSTponghYZCZ+Q4ex/algaqDcxgKsG2ZqkEAPGE7NRSIkolSlNxP/Fm IoNjMwFP2ohNdA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrheelgdduudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevveefveefueegffekkefhgeeiueffgfetueejvdfg hfeujeejhfekjeelgedtgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Feb 2022 13:37:43 -0500 (EST) Subject: Re: DELETING then INSERTING record with same PK in the same TRANSACTION To: Andrew Hardy , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Wed, 9 Feb 2022 10:37:42 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/9/22 10:11 AM, Andrew Hardy wrote: > Hi, > > When I: > > Begin a transaction > DELETE from where id (PK) = > INSERT INTO
VALUES () > ... > ... > ... > COMMIT > > I get > > insert into "itinerary" ("dk", "locator") values ($1, $2) - duplicate > key value violates unique constraint "itinerary_pkey"
= itinerary? What fields is unique constraint "itinerary_pkey" actually pointing at? There should be more to the error message. Can you provide the complete message? > > Do I need some particular kind of settings on my transaction to be able > to delete and insert afresh in the same transaction? > > In case it is relevant - the first delete will lead to cascaded deletes > on children. > > Alternatively I wonder if I change the PK column value to > "-FORDELETION" will I be free to insert under the same > original PK value in the same transaction, then delete the FORDELETE > item just before committing or will I hit the same issue? > > Thanks, > > Andrew > > -- Adrian Klaver adrian.klaver@aklaver.com