Re: [PATCH] rename column if exists

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
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 14:40:24
Message-ID: 416331.1636123224@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Friday, November 5, 2021, Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
>> I know that, I'm just not convinced that it's a feature (in the case at
>> hand)

> I don’t see how this one should be expected to meet a higher bar than drop
> table or other existing commands. I get why in the nearby discussion
> create role if not exists is treated differently based upon its unique
> security concerns. Does column renaming have a hidden concern I’m not
> thinking of?

IMV, the best forms of these options are the ones that produce a known
end state of the object. DROP IF EXISTS meets that test: upon successful
completion, the object doesn't exist. CREATE OR REPLACE meets that test:
upon successful completion, the object exists and has exactly the
properties stated in the command. CREATE IF NOT EXISTS fails that test,
because while you know that the object will exist afterwards, you've got
next to no information about its properties. We've put up with C.I.N.E.
semantics in some limited cases like CREATE TABLE, where C.O.R.
semantics would be too drastic; but IMO it's generally best avoided.

In this framework, RENAME IF EXISTS is in sort of a weird place.
You'd know that afterwards there is no longer any column with the
source name. But you are not entitled to draw any conclusions
about whether a column exists with the target name, nor what its
properties are. So that makes me feel like the semantics are more
on the poorly-defined than well-defined side of the fence.

I'd be more willing to overlook that if a clear use-case had been
given, but AFAICS no concrete case has been offered.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthias van de Meent 2021-11-05 14:45:51 Re: Parallel vacuum workers prevent the oldest xmin from advancing
Previous Message Robert Haas 2021-11-05 14:37:33 Re: pg14 psql broke \d datname.nspname.relname