pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: etolnay@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form <noreply@postgresql.org>
Subject: Re: BUG #15087: ALTER INDEX RENAME renames table if matches
Date: Mon, 26 Feb 2018 01:20:25 +0100
Message-ID: <3f64815f-8ce6-929d-9e8a-5affc9d9091d@2ndquadrant.com> (raw)
In-Reply-To: <151960070775.21248.1471444285595717214@wrigleys.postgresql.org>
References: <151960070775.21248.1471444285595717214@wrigleys.postgresql.org>


On 02/26/2018 12:18 AM, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      15087
> Logged by:          Ezequiel Tolnay
> Email address:      etolnay@gmail.com
> PostgreSQL version: 10.0
> Operating system:   Windows 10
> Description:        
> 
> A table name mytable can be renamed to newtable via:
> 
> ALTER INDEX mytable RENAME TO newtable
> 
> This is probably incorrect. It should either raise an error (as it does with
> ALTER TABLE if the name supplied is that of an index), or better, when
> specified IF EXISTS, simply do nothing.
> 

Hmmm, I agree that seems suspicious and surprising. But looking at the
code, I see that RangeVarCallbackForAlterRelation does this:

    /*
     * For compatibility with prior releases, we allow ALTER TABLE to
     * be used with most other types of relations (but not composite
     * types). We allow similar flexibility for ALTER INDEX in the case
     * of RENAME, but not otherwise.  Otherwise, the user must select
     * the correct form of the command for the relation at issue.
     */

    ...

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

So the behavior seems intentional, because of backwards compatibility.

I personally wouldn't mind changing it - it certainly seems surprising,
and singling out RENAME seems strange. But maybe it'd break more things
than I imagine.


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




view thread (2+ messages)

Message-ID: <3f64815f-8ce6-929d-9e8a-5affc9d9091d@2ndquadrant.com>
Permalink:  ../3f64815f-8ce6-929d-9e8a-5affc9d9091d@2ndquadrant.com/
Also on:    postgresql.org/message-id/3f64815f-8ce6-929d-9e8a-5affc9d9091d@2ndquadrant.com

 · 

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: tomas.vondra@2ndquadrant.com, noreply@postgresql.org
  Subject: Re: BUG #15087: ALTER INDEX RENAME renames table if matches
  In-Reply-To: <3f64815f-8ce6-929d-9e8a-5affc9d9091d@2ndquadrant.com>
  References: <151960070775.21248.1471444285595717214@wrigleys.postgresql.org> <3f64815f-8ce6-929d-9e8a-5affc9d9091d@2ndquadrant.com>

* 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