Re: BUG #15865: ALTER TABLE statements causing "relation already exists" errors when some indexes exist

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Keith Fiske <keith.fiske@crunchydata.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>, pgsql-bugs@lists.postgresql.org
Date: 2019-06-24T19:05:30Z
Lists: pgsql-bugs, pgsql-hackers

Attachments

I wrote:
> As before, I attach a patch against HEAD, plus one that assumes e76de8861
> has been reverted first, which is likely easier to review.
> Unlike yesterday, I'm feeling pretty good about this patch now, but it
> still wouldn't hurt for somebody else to go over it.

I started to back-patch this, and soon noticed that the content of the
OCLASS_CONSTRAINT case branch in ATExecAlterColumnType has varied across
versions, which makes copy-and-pasting it seem pretty hazardous.  Hence
it seems prudent to do slightly more work and split that code out into
a subroutine rather than having two copies.  As attached, which is a
hopefully-final patch for HEAD.  As before, it presumes reversion of
e76de8861, because it's a lot easier to see what's going on that way.

BTW ... while working on this, I got annoyed by the fact that
ATExecAlterColumnGenericOptions was inserted, no doubt with the aid of a
dartboard, into the middle of a large group of AlterColumnType-related
functions.  Would anyone mind a separate patch to relocate it down
past those, probably just before ATExecChangeOwner?


			regards, tom lane

Commits

  1. Simplify psql \d's rule for ordering the indexes of a table.

  2. Purely-cosmetic adjustments in tablecmds.c.

  3. Further fix ALTER COLUMN TYPE's handling of indexes and index constraints.

  4. Fix ALTER COLUMN TYPE failure with a partial exclusion constraint.