Re: wrong hint message for ALTER FOREIGN TABLE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Shigeru Hanada <hanada(at)metrosystems(dot)co(dot)jp>, "pgsql-hackers >> PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: wrong hint message for ALTER FOREIGN TABLE
Date: 2011-04-26 00:02:34
Message-ID: 23442.1303776154@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Mon, Apr 25, 2011 at 7:03 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> As per the other thread today, this advice would usually be correct,
>> so I think that not offering any advice at all would be a step down from
>> that.

> Well, currently ALTER TABLE will work even if the argument is a view
> or sequence, but I view that as a backwards-compatibility kludge we
> should be looking to move away from, not something we want to further
> bake in. However, I'm out of time to bikeshed on this issue, so fix
> it however you like.

Well, actually, having looked at the proposed patch in context I now
agree with Shigeru-san's fix:

/*
* For compatibility with prior releases, we don't complain if ALTER TABLE
* or ALTER INDEX is used to rename some other type of relation. But
* ALTER SEQUENCE/VIEW/FOREIGN TABLE are only to be used with relations of
* that type.
*/
if (reltype == OBJECT_SEQUENCE && relkind != RELKIND_SEQUENCE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a sequence",
RelationGetRelationName(targetrelation))));

if (reltype == OBJECT_VIEW && relkind != RELKIND_VIEW)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a view",
RelationGetRelationName(targetrelation))));

if (reltype == OBJECT_FOREIGN_TABLE && relkind != RELKIND_FOREIGN_TABLE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a foreign table",
RelationGetRelationName(targetrelation)),
errhint("Use ALTER FOREIGN TABLE instead.")));

/*
* Don't allow ALTER TABLE on composite types. We want people to use ALTER
* TYPE for that.
*/
if (relkind == RELKIND_COMPOSITE_TYPE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is a composite type",
RelationGetRelationName(targetrelation)),
errhint("Use ALTER TYPE instead.")));

If we haven't felt a need for HINTs for the ALTER SEQUENCE or ALTER VIEW
cases, it seems unlikely that we need one for ALTER FOREIGN TABLE.
Probably whoever wrote this was analogizing to the ALTER TABLE/TYPE case
after it, but that's not the same kind of situation, as evidenced by the
fact that the primary error message is worded differently.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2011-04-26 00:12:11 Re: Improving the memory allocator
Previous Message Tom Lane 2011-04-25 23:48:42 Re: branching for 9.2devel