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 1i0SpQ-0003fN-Kp for pgsql-general@arkaria.postgresql.org; Wed, 21 Aug 2019 15:47:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i0SpP-0001HN-7y for pgsql-general@arkaria.postgresql.org; Wed, 21 Aug 2019 15:47:15 +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 1i0SpO-0001HF-7S for pgsql-general@lists.postgresql.org; Wed, 21 Aug 2019 15:47:14 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i0SpK-0004Nh-97 for pgsql-general@postgresql.org; Wed, 21 Aug 2019 15:47:13 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 07D5F2108A; Wed, 21 Aug 2019 11:47:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 21 Aug 2019 11:47:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=p 3ulmkgkBm/+TiZa8uHkf+MIBMFMImf2ivf/4Pd/F/U=; b=pO3V1ZEDbyYq4lvJS ilv3P9wf8zEWD4YU4d6Hbfn0aVwxXANWERZ92pcbXLl0d0EO3O/PLqmror2zm8E9 JTxDTLORarVaap6c3AXKqrso3C911rVMdnlk+VFqqczPtvrwfyCTiiH6qGo7PpDN 9Eed6ugm0rm29MQyLXU0kN0ayUFXXkogVQnSSsvdi3yxJo68fy3uldT0BW/bvimc swoBM0Y3wlSJjU4ikPdNYbRiyp2Z5s9tCE1jFeLDT+ygp/8irgmTCYkJceyxHApM RRE8SsEqQIALj89DTiVkyD5Mz9QO/ggit6Ps3WX4RK/yPhd+1k1Pw0xH/tL3APfw V8Q2w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm3; bh=p3ulmkgkBm/+TiZa8uHkf+MIBMFMImf2ivf/4Pd/F /U=; b=ug4eyuFBq+CxIWSgI6Ce43vczSINt55aOlQ9gfOz9YMseEkVdYtKaBMym /LsLNIwaLvGKMr6LBmqEZ34JqUc0OxscaTjOm0uovMYUPQfkb0fengfJIHpQz0fo CTWOt0mjKBfatcZyPkdEEKR+mkvBJlBdd9DdCa/ydVLXs7Qcfw/lBgU9RZqoMd0o kGwnW//ie/BctBZmlMNFhqRzrf1cA08vvrefFw3SMWN3Y9mnqo6hDpsYC3QuwLnZ VTF2OawgFrEvJriUwEBw+/V+GYgjlbcaew/nRBLI+NXKMh6lijROwTlAsOl2+lEy Zd2Jf8VoGcB/JccYDdHDUU75roLyg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudegfedgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphepudejgedrvddurdeirddvhedunecurfgrrhgrmhepmhgrihhlfhhrohhm pegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrh fuihiivgeptd X-ME-Proxy: Received: from ranger.suse (174-21-6-251.tukw.qwest.net [174.21.6.251]) by mail.messagingengine.com (Postfix) with ESMTPA id CF96780059; Wed, 21 Aug 2019 11:47:06 -0400 (EDT) Subject: Re: Rename a column if not already renamed.? To: "Day, David" , Tom Lane Cc: Luca Ferrari , "pgsql-general@postgresql.org" References: <17271.1566334606@sss.pgh.pa.us> From: Adrian Klaver Message-ID: Date: Wed, 21 Aug 2019 08:47:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 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 8/21/19 7:52 AM, Day, David wrote: > I agree the function could be improved to deal with both old and new name existing simultaneously. > That is almost certainly the root cause, and one that I would confirm if the tester and site were currently available to me. > > Our work flow for this scenario is something like: > > 1. 9.6 pg_dump takes a snapshot of our 9.6 database. > 2. Postgres is upgraded/freshly installed to 11.3.. > 3. The 9.6 database is restored using the version 11 pg_restore tool. In 3) you are restoring to the new 11.3 instance, correct? > > 4. Once our application process starts up, it sees there is a patch available in it's old branch that is one greater then it's restored 9.6 content. > That happens to be a merge patch which resets the expectations. > It attempts to apply all patches in the new branch since the point of divergence and runs into my current issue. > > It occurs to me I could simply put an exception handler in the rename column function and I would likely proceed merrily along. > But curiosity is killing me and the cat. What is causing the old name to persist in the pg_attribute table after the rename. ? If you are indeed working on the new instance pg_attribute would have no 'memory' of the dropped column. It would seem to me to come down to what is passed into sys.rename_column() as old_name_, new_name. > > Would a stale function referencing the old column name be a contributor? > > > Regards > > > Dave Day > > > > > -----Original Message----- > From: Tom Lane [mailto:tgl@sss.pgh.pa.us] > Sent: Tuesday, August 20, 2019 4:57 PM > To: Day, David > Cc: Luca Ferrari ; pgsql-general@postgresql.org > Subject: Re: Rename a column if not already renamed.? > > "Day, David" writes: >> The error is something like column already exists and > > Not sure about the workflow this function is used within, but maybe you need to consider what to do when both the old and new column names exist. > Because that sure sounds like what is happening. > > regards, tom lane > > > > > -- Adrian Klaver adrian.klaver@aklaver.com