Index

Started by Sonam Sharmaover 6 years ago3 messagesgeneral
Jump to latest
#1Sonam Sharma
sonams1209@gmail.com

I have created indexes with certain set of columns. Now I want to remove
one of the column and add new column. Can this done without dropping the
index?

#2Luca Ferrari
fluca1978@gmail.com
In reply to: Sonam Sharma (#1)
Re: Index

On Fri, Oct 25, 2019 at 7:35 AM Sonam Sharma <sonams1209@gmail.com> wrote:

I have created indexes with certain set of columns. Now I want to remove one of the column and add new column. Can this done without dropping the index?

If you are going to rename the column the answer is yes.
If you are going to drop the column that would also invalidate and
drop the index.
If you are changing the data type the index should remain in place.

See <https://www.postgresql.org/docs/12/sql-altertable.html&gt; in
particular paragraph about 'DROP COLUMN' and 'SET DATA TYPE'.

Luca

#3Ravi Krishna
sr_krishna@aol.com
In reply to: Sonam Sharma (#1)
Re: Index

I have created indexes with certain set of columns. Now I want to remove one of the column and add new column. Can this done without dropping the index?

If you intent is to avoid taking that table offline while the index is being built, you can do this:

1. create index concurrently on the new set of columns
2. once (1) done drop old index