Why can't different postgres tables use indexes with the same name?
I'm trying to alter a number of tables from basic tables to monthly partitioned tables. The normal solution seems to be
- Create a partitioned copy (empty) of the source table
CREATE TABLE copy (LIKE original INCLUDING INDEXES) PARTITION BY RANGE xxxx
- Copy the data from source table to the copy.
INSERT INTO copy (SELECT * FROM original WHERE ???)
- Drop the source
DROP TABLE original
- Rename the partitioned table.
ALTER TABLE copy RENAME TO original
My current issue is that although the CREATE TABLE ... LIKE ... INCLUDING INDEXES
will use all the same field names and datatypes, it will make up a new set of index names. For a variety of reasons, the indexes on these databases need to conform to a fixed naming convention.
Is there a way of copying a table and copying the index names to?