RENAME INDEX

On this page Carat arrow pointing down
Warning:
As of October 4, 2019, CockroachDB v2.0 is no longer supported. For more details, refer to the Release Support Policy.

The RENAME INDEX statement changes the name of an index for a table.

Note:
It is not possible to rename an index referenced by a view. For more details, see View Dependencies.

Synopsis

ALTER INDEX IF EXISTS table_name @ index_name RENAME TO index_name

Required Privileges

The user must have the CREATE privilege on the table.

Parameters

Parameter Description
IF EXISTS Rename the index only if an index current_name exists; if one does not exist, do not return an error.
table_name The name of the table with the index you want to use
index_name The current name of the index
name The name you want to use for the index, which must be unique to its table and follow these identifier rules.

Example

Rename an Index

> SHOW INDEXES FROM users;
+-------+----------------+--------+-----+--------+-----------+---------+----------+
| Table |      Name      | Unique | Seq | Column | Direction | Storing | Implicit |
+-------+----------------+--------+-----+--------+-----------+---------+----------+
| users | primary        | true   |   1 | id     | ASC       | false   | false    |
| users | users_name_idx | false  |   1 | name   | ASC       | false   | false    |
| users | users_name_idx | false  |   2 | id     | ASC       | false   | true     |
+-------+----------------+--------+-----+--------+-----------+---------+----------+
(3 rows)
> ALTER INDEX users@users_name_idx RENAME TO name_idx;
RENAME INDEX
> SHOW INDEXES FROM users;
+-------+----------+--------+-----+--------+-----------+---------+----------+
| Table |   Name   | Unique | Seq | Column | Direction | Storing | Implicit |
+-------+----------+--------+-----+--------+-----------+---------+----------+
| users | primary  | true   |   1 | id     | ASC       | false   | false    |
| users | name_idx | false  |   1 | name   | ASC       | false   | false    |
| users | name_idx | false  |   2 | id     | ASC       | false   | true     |
+-------+----------+--------+-----+--------+-----------+---------+----------+
(3 rows)

See Also


Yes No
On this page

Yes No