88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.310 2009/12/15 04:57:47 rhaas Exp $
11+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.311 2009/12/23 16:43:43 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -1905,17 +1905,6 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
19051905
19061906/*
19071907 *renameatt- changes the name of a attribute in a relation
1908- *
1909- *Attname attribute is changed in attribute catalog.
1910- *No record of the previous attname is kept (correct?).
1911- *
1912- *get proper relrelation from relation catalog (if not arg)
1913- *scan attribute catalog
1914- *for name conflict (within rel)
1915- *for original attribute (if not arg)
1916- *modify attname in attribute tuple
1917- *insert modified attribute in attribute catalog
1918- *delete original attribute from attribute catalog
19191908 */
19201909void
19211910renameatt (Oid myrelid ,
@@ -1929,8 +1918,6 @@ renameatt(Oid myrelid,
19291918HeapTuple atttup ;
19301919Form_pg_attribute attform ;
19311920int attnum ;
1932- List * indexoidlist ;
1933- ListCell * indexoidscan ;
19341921
19351922/*
19361923 * Grab an exclusive lock on the target table, which we will NOT release
@@ -2024,7 +2011,8 @@ renameatt(Oid myrelid,
20242011errmsg ("cannot rename inherited column \"%s\"" ,
20252012oldattname )));
20262013
2027- /* should not already exist */
2014+ /* new name should not already exist */
2015+
20282016/* this test is deliberately not attisdropped-aware */
20292017if (SearchSysCacheExists (ATTNAME ,
20302018ObjectIdGetDatum (myrelid ),
@@ -2035,6 +2023,7 @@ renameatt(Oid myrelid,
20352023errmsg ("column \"%s\" of relation \"%s\" already exists" ,
20362024newattname ,RelationGetRelationName (targetrelation ))));
20372025
2026+ /* apply the update */
20382027namestrcpy (& (attform -> attname ),newattname );
20392028
20402029simple_heap_update (attrelation ,& atttup -> t_self ,atttup );
@@ -2044,63 +2033,6 @@ renameatt(Oid myrelid,
20442033
20452034heap_freetuple (atttup );
20462035
2047- /*
2048- * Update column names of indexes that refer to the column being renamed.
2049- */
2050- indexoidlist = RelationGetIndexList (targetrelation );
2051-
2052- foreach (indexoidscan ,indexoidlist )
2053- {
2054- Oid indexoid = lfirst_oid (indexoidscan );
2055- HeapTuple indextup ;
2056- Form_pg_index indexform ;
2057- int i ;
2058-
2059- /*
2060- * Scan through index columns to see if there's any simple index
2061- * entries for this attribute.We ignore expressional entries.
2062- */
2063- indextup = SearchSysCache (INDEXRELID ,
2064- ObjectIdGetDatum (indexoid ),
2065- 0 ,0 ,0 );
2066- if (!HeapTupleIsValid (indextup ))
2067- elog (ERROR ,"cache lookup failed for index %u" ,indexoid );
2068- indexform = (Form_pg_index )GETSTRUCT (indextup );
2069-
2070- for (i = 0 ;i < indexform -> indnatts ;i ++ )
2071- {
2072- if (attnum != indexform -> indkey .values [i ])
2073- continue ;
2074-
2075- /*
2076- * Found one, rename it.
2077- */
2078- atttup = SearchSysCacheCopy (ATTNUM ,
2079- ObjectIdGetDatum (indexoid ),
2080- Int16GetDatum (i + 1 ),
2081- 0 ,0 );
2082- if (!HeapTupleIsValid (atttup ))
2083- continue ;/* should we raise an error? */
2084-
2085- /*
2086- * Update the (copied) attribute tuple.
2087- */
2088- namestrcpy (& (((Form_pg_attribute )GETSTRUCT (atttup ))-> attname ),
2089- newattname );
2090-
2091- simple_heap_update (attrelation ,& atttup -> t_self ,atttup );
2092-
2093- /* keep system catalog indexes current */
2094- CatalogUpdateIndexes (attrelation ,atttup );
2095-
2096- heap_freetuple (atttup );
2097- }
2098-
2099- ReleaseSysCache (indextup );
2100- }
2101-
2102- list_free (indexoidlist );
2103-
21042036heap_close (attrelation ,RowExclusiveLock );
21052037
21062038relation_close (targetrelation ,NoLock );/* close rel but keep lock */