Thread: Renaming tables and their indexes simultaneously

Renaming tables and their indexes simultaneously

From
Moshe Jacobson
Date:
I have a stored procedure that renames a table as part of a partitioning scheme, then re-creates it.
Up until recently (I'm not sure what changed), renaming the table would cause the pkey index/constraint, as well as all other indexes, to be renamed according to the new table name.
However, they now do not rename, and cause collisions when the new table is created.

I would prefer not having to drop and re-create the primary key index, as it takes quite a while to drop and re-create an index that large.

How can I cause Postgres to rename the table's attached indexes when I rename the table, and what might have caused it to stop doing so recently?

We are on Postgres 9.1, but we did not recently upgrade...

Thanks.

--
Moshe Jacobson
Nead Werx, Inc. | Senior Systems Engineer
2323 Cumberland Parkway, Suite 201 | Atlanta, GA 30339
moshe@neadwerx.com | 
www.neadwerx.com

Re: Renaming tables and their indexes simultaneously

From
Tom Lane
Date:
Moshe Jacobson <moshe@neadwerx.com> writes:
> I have a stored procedure that renames a table as part of a partitioning
> scheme, then re-creates it.
> Up until recently (I'm not sure what changed), renaming the table would
> cause the pkey index/constraint, as well as all other indexes, to be
> renamed according to the new table name.

Really?  AFAICT, we've never done that --- at least not as far back as
7.2, which is as far as I felt like checking.

There did use to be some logic in there that tried to make index column
names track their underlying columns when you renamed a column.  But
we gave up on that in 9.0, mainly because of index-expression cases.

            regards, tom lane