The attached patch works for my case... regression=# create table test (id serial, col1 varchar(64)); NOTICE: CREATE TABLE will create implicit sequence 'test_id_seq' for SERIAL column 'test.id' NOTICE: CREATE TABLE/UNIQUE will create implicit index 'test_id_key' for table 'test' CREATE regression=# create index i_t_c on test(col1); CREATE regression=# alter table test rename col1 to col2; ALTER regression=# \d test Table "test" Column | Type | Modifiers --------+-----------------------+------------------------------------------------- id | integer | not null default nextval('"test_id_seq"'::text) col2 | character varying(64) | Indexes: i_t_c Unique keys: test_id_key
regression=# \d itc Did not find any relation named "itc". regression=# \d i_t_c Index "i_t_c" Column | Type --------+----------------------- col2 | character varying(64) btree wooohoo!!! Of course, it would be best if someone else looked this code over, because I get the feeling there is an easier way to get this done. The only thing I can say is that it solves my problem and does not /appear/ to create any others. cheers. Brent p.s., I appreciate the gurus not jumping in with the quick fix -- The experience has been fun :-) -- "Develop your talent, man, and leave the world something. Records are really gifts from people. To think that an artist would love you enough to share his music with anyone is a beautiful thing." -- Duane Allman
Index: src/backend/commands/rename.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/commands/rename.c,v retrieving revision 1.57 diff -r1.57 rename.c 35a36,37 > static void > update_indexed_attnames(Oid indrelid, const char *_old, const char *_new); 169a172,235 > > update_indexed_attnames(relid,oldattname,newattname); > > } > > /* man, I want some sql here... > * > * UPDATE pg_attribute > * SET attname='$3' > * WHERE indrelid=$1 AND attname='$2' > */ > static void > update_indexed_attnames(Oid indrelid, > const char *oldattname, > const char *newattname) > { > List *indexoidlist; > List *indexoidscan; > Relation relation; > Relation attrelation; > > relation = heap_open(indrelid, AccessShareLock); > indexoidlist = RelationGetIndexList(relation); > > attrelation = heap_openr(AttributeRelationName, RowExclusiveLock); > > foreach(indexoidscan, indexoidlist) > { > HeapTuple atttup; > Oid indexoid; > indexoid = lfirsti(indexoidscan); > elog(DEBUG,"update_indexed_attnames: indexoid: %d", indexoid); > atttup = SearchSysCacheCopy(ATTNAME, > >ObjectIdGetDatum(indexoid), > >PointerGetDatum(oldattname), > 0, 0); > if (!HeapTupleIsValid(atttup)){ > elog(DEBUG, "update_indexed_attnames: not updating %d.", >indexoid); > } > else{ > elog(DEBUG, "update_indexed_attnames: updating %d.", indexoid); > > > StrNCpy(NameStr(((Form_pg_attribute) GETSTRUCT(atttup))->attname), > newattname, NAMEDATALEN); > > simple_heap_update(attrelation, &atttup->t_self, atttup); > > /* keep system catalog indices current */ > { > Relation irelations[Num_pg_attr_indices]; > > CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, >irelations); > CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, >atttup); > CatalogCloseIndices(Num_pg_attr_indices, irelations); > } > heap_freetuple(atttup); > } > } > > freeList(indexoidlist); > > heap_close(attrelation, RowExclusiveLock); > heap_close(relation, AccessShareLock);
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster