Re: [PATCH] rename column if exists

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: David Oksman <oksman(dot)dav(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] rename column if exists
Date: 2021-11-05 09:21:42
Message-ID: 79423E73-C567-403C-A30F-1A9695BBB8F6@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 4 Nov 2021, at 14:26, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> On Thursday, November 4, 2021, Daniel Gustafsson <daniel(at)yesql(dot)se <mailto:daniel(at)yesql(dot)se>> wrote:
> > On 22 Mar 2021, at 20:40, David Oksman <oksman(dot)dav(at)gmail(dot)com <mailto:oksman(dot)dav(at)gmail(dot)com>> wrote:
> >
> > Added the ability to specify IF EXISTS when renaming a column of an object (table, view, etc.).
> > For example: ALTER TABLE distributors RENAME COLUMN IF EXISTS address TO city;
> > If the column does not exist, a notice is issued instead of throwing an error.
>
> What is the intended use-case for RENAME COLUMN IF EXISTS? I'm struggling to
> see when that would be helpful to users but I might not be imaginative enough.
>
> Same reasoning as for all the other if exists we have, idempotence. Being able to run the command on an object that is already in the desired state without provoking an error.

If the object is known to be in the desired state, there is no need to use IF
EXISTS. Personally I think IF EXISTS commands are useful when they provide a
transition to a known end state, but in this case it's an unknown end state.

--
Daniel Gustafsson https://vmware.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2021-11-05 09:39:36 Re: [PATCH] Added TRANSFORM FOR for COMMENT tab completion
Previous Message Amit Kapila 2021-11-05 08:49:01 Re: row filtering for logical replication