Re: [PATCH] rename column if exists

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Daniel Gustafsson <daniel(at)yesql(dot)se>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, 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 15:47:48
Message-ID: CAKFQuwZc7JU57PW=9JAFLZNWkwKhbQ+OuOrLby_qQeK-HbquTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 5, 2021 at 8:08 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> > On Friday, November 5, 2021, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >> I'd be more willing to overlook that if a clear use-case had been
> >> given, but AFAICS no concrete case has been offered.
>
> > The use case is the exact same one for all of these - indempotence,
>
> ... except that, as I explained, it's NOT really idempotent.
> It's a sort of half-baked idempotence, which is exactly the kind
> of underspecification you complain about in your next sentence.
> Do we really want to go there?
>
>
It may not be self-contained idempotence but so long as the user is using
the command in the expected manner the end result will appear that way.

I disagree with the premise that we have to meet the known end state
requirement. In the imagined use case either, but not both, the original
column or the result column are going to exist. A RIE will behave as
expected and desired in that case. If someone executes RIE in a case where
neither column exists the end result is no error and neither column still
exists. This is exactly what the command RIE promises will happen in that
case. It works reliably and as one would expect and from there it is up to
the user, not us, to decide when it is appropriate to use or not.

The perspective I'm coming from is that it's not terribly hard
> to write whatever sort of conditional DDL you want using plpgsql
> DO blocks, so it's not like we lack the capability. I think we
> should only provide pre-fab conditional DDL for the most basic,
> solidly-defined cases; and it seems to me that RENAME IF EXISTS
> isn't solid enough.
>
>
IOW, it doesn't actually matter what the use case is. And the definition
of solid basically precludes anything except CREATE and DROP commands
(including the create version written ALTER TABLE IF EXISTS <do something>).

If this is indeed the agreed upon standard for this kind of thing an FAQ or
documentation entry formalizing it would help, because lots of people are
just going to see that we meet this migration use case only partially and
will continue to request and even develop the missing pieces.

David J.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2021-11-05 15:50:01 Re: refactoring basebackup.c
Previous Message Robert Haas 2021-11-05 15:37:22 Re: [PATCH] rename column if exists