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 1i0Ryk-0001Vy-3M for pgsql-general@arkaria.postgresql.org; Wed, 21 Aug 2019 14:52:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Ryh-0007il-Ga for pgsql-general@arkaria.postgresql.org; Wed, 21 Aug 2019 14:52:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i0Ryh-0007Y9-1P for pgsql-general@lists.postgresql.org; Wed, 21 Aug 2019 14:52:47 +0000 Received: from smtp1.redcom.com ([192.86.3.143]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1i0Rye-0001m6-E2 for pgsql-general@postgresql.org; Wed, 21 Aug 2019 14:52:45 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp1.redcom.com (Postfix) with ESMTP id CC1BAA245; Wed, 21 Aug 2019 10:52:43 -0400 (EDT) X-Virus-Scanned: amavisd-new at redcom.com Received: from smtp1.redcom.com ([127.0.0.1]) by localhost (smtp1.redcom.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OSKhAu+PRGWm; Wed, 21 Aug 2019 10:52:41 -0400 (EDT) Received: from pie.redcom.com (pie [192.168.33.15]) by smtp1.redcom.com (Postfix) with ESMTP id 31310A234; Wed, 21 Aug 2019 10:52:41 -0400 (EDT) Received: from exch-02.redcom.com (exch-03.redcom.com [192.168.32.32]) by pie.redcom.com (8.11.7p1+Sun/8.10.2) with ESMTP id x7LEqef07645; Wed, 21 Aug 2019 10:52:40 -0400 (EDT) Received: from exch-03.redcom.com (fd00::8549:68c0:3d5f:ee62) by exch-03.redcom.com (fd00::8549:68c0:3d5f:ee62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.330.5; Wed, 21 Aug 2019 10:52:40 -0400 Received: from exch-03.redcom.com ([fe80::a442:ce34:c9c8:268f]) by exch-03.redcom.com ([fe80::a442:ce34:c9c8:268f%3]) with mapi id 15.02.0330.005; Wed, 21 Aug 2019 10:52:40 -0400 From: "Day, David" To: Tom Lane CC: Luca Ferrari , "pgsql-general@postgresql.org" Subject: RE: Rename a column if not already renamed.? Thread-Topic: Rename a column if not already renamed.? Thread-Index: AdVXikX1liX7eXu6QciLSjE751XxEwAJmwSAAAg32aD//9N5AP//G/IQ Date: Wed, 21 Aug 2019 14:52:40 +0000 Message-ID: References: <17271.1566334606@sss.pgh.pa.us> In-Reply-To: <17271.1566334606@sss.pgh.pa.us> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.84.42] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I agree the function could be improved to deal with both old and new name e= xisting simultaneously. That is almost certainly the root cause, and one that I would confirm if t= he tester and site were currently available to me. =20 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. 4. Once our application process starts up, it sees there is a patch availab= le 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 diver= gence and runs into my current issue.=20 =20 It occurs to me I could simply put an exception handler in the rename colum= n function and I would likely proceed merrily along. But curiosity is killing me and the cat. What is causing the old name to pe= rsist in the pg_attribute table after the rename. ? 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]=20 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 nee= d 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