Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add column to existing multi-column index

Tags:

indexing

mysql

In my table I have a multi-column index for the columns (name,folder)

I recently added a new column called date and I want to put an index into it, but I want to put it into the existing multi-column index

When I do Alter table books add index theindex (date); I get Duplicate key name 'theindex'

How do I add another column to an index without creating a new key?

like image 209
user4757174 Avatar asked Nov 07 '16 01:11

user4757174


People also ask

How do I replace an index column with another column?

You can change the index to a different column by using set_index() after reset_index() .

How do I convert multiple index to columns in pandas?

pandas MultiIndex to ColumnsUse pandas DataFrame. reset_index() function to convert/transfer MultiIndex (multi-level index) indexes to columns. The default setting for the parameter is drop=False which will keep the index values as columns and set the new index to DataFrame starting from zero.

How do I change multiple indexes to single index in pandas?

Output: Now, the dataframe has Hierarchical Indexing or multi-indexing. To revert the index of the dataframe from multi-index to a single index using the Pandas inbuilt function reset_index(). Returns: (Data Frame or None) DataFrame with the new index or None if inplace=True.


1 Answers

Just change the syntax to the below way to add new columns to the index:

ALTER table `books` DROP INDEX theindex;
ALTER table `books` ADD INDEX theindex (`date`, `time`);
like image 58
Praveen Kumar Purushothaman Avatar answered Oct 05 '22 01:10

Praveen Kumar Purushothaman