32

If I'm dropping and re-creating a Postgres table that is indexed, will the index still exist?

Do I need to drop and re-index the table after re-creating it or do I just need to re-create the index on the new table and leave the cleaning up of the old index to Postgres?

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
  • 1
    Why didn't you try it out? The index gets dropped when the table is dropped. Automatically generated indexes (e.g. primary key, unique) will be re-created when the table is re-created, manually created indexes won't. You cannot have an index without an associated table. – dhke Jul 20 '16 at 13:28

1 Answers1

54

Drop table will delete all related constraints, & index, no need for you to do any kind of cleanup. Postgres will handle that.

131
  • 3,071
  • 31
  • 32