pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Tom Lane <tgl@sss.pgh.pa.us>
To: Réal A. Carbonneau <contact@realcarbonneau.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: ERROR: cannot change name of view column
Date: Tue, 01 Jan 2019 13:18:29 -0500
Message-ID: <6692.1546366709@sss.pgh.pa.us> (raw )
In-Reply-To: <CAJ-S0v57o6Ltgij0zBRnHLK2ustVsM7XinJJF8geJpamq-ortA@mail.gmail.com >
References: <CAJ-S0v57o6Ltgij0zBRnHLK2ustVsM7XinJJF8geJpamq-ortA@mail.gmail.com >
=?UTF-8?Q?R=C3=A9al_A=2E_Carbonneau?= <contact@realcarbonneau.com> writes:
> Changing the name of any column in a view gives the error "ERROR: cannot
> change name of view column".
In CREATE OR REPLACE VIEW, you mean? Yeah, that's intentional.
> Thus, the original error message is not completely correct. Ideally,
> the CREATE OR REPLACE VIEW would automatically apply the ALTER TABLE ...
> RENAME COLUMN (or underlying procedure) since it is available and fulfills
> the original DDL request, thus making the error message unnecessary.
DWIM doesn't seem like a good idea here to me. Doing what you suggest
would be far more likely to let mistakes get by undetected than to
actually do what the user intended. In many cases, the column types
are all alike, so that the column names are the only cross-check there
is that the new view definition matches up with the old.
For example, suppose you originally wrote
CREATE VIEW v AS SELECT x, y FROM ...
and then you want to change something in the FROM clause, but you
fat-finger the replacement command as
CREATE OR REPLACE VIEW v AS SELECT x, z FROM ...
If y and z are of the same datatype, this would pass undetected
if we try to be "helpful" in this way.
Another class of examples involves accidentally switching the order of
view output columns. This would interact especially badly with the
fact that we do allow CREATE OR REPLACE VIEW to append columns.
If you should have written
CREATE OR REPLACE VIEW v AS SELECT x, y, z FROM ...
to add "z" to the original list, but get the order wrong, this proposal
would allow very serious breakage of existing view users to occur.
(Previously-stored views will refer to those columns by number, not name,
which is really necessary to allow ALTER VIEW RENAME COLUMN to work at
all.)
> Or at the very least, the error message could be changed to suggest using
> the ALTER TABLE ... RENAME COLUMN until the feature is included in the
> CREATE OR REPLACE VIEW.
Perhaps there's room for a "HINT: if you intended to change view
column names, use ALTER VIEW RENAME COLUMN". But I suspect such
a hint would get printed in many cases where it didn't apply,
making it perhaps more confusing not less.
regards, tom lane
view thread (6+ messages) latest in thread
Message-ID: <6692.1546366709@sss.pgh.pa.us>
Permalink: ../6692.1546366709@sss.pgh.pa.us/
Also on: postgresql.org/message-id/6692.1546366709@sss.pgh.pa.us
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, contact@realcarbonneau.com
Subject: Re: ERROR: cannot change name of view column
In-Reply-To: <6692.1546366709@sss.pgh.pa.us>
References: <CAJ-S0v57o6Ltgij0zBRnHLK2ustVsM7XinJJF8geJpamq-ortA@mail.gmail.com> <6692.1546366709@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox