At what level do Postgres index names need to be unique?

Indexes and tables (and views, and sequences, and…) are stored in the pg_class catalog, and they’re unique per schema due to a unique key on it:

# \d pg_class
      Table "pg_catalog.pg_class"
     Column     |   Type    | Modifiers 
----------------+-----------+-----------
 relname        | name      | not null
 relnamespace   | oid       | not null
 ...
Indexes:
    "pg_class_oid_index" UNIQUE, btree (oid)
    "pg_class_relname_nsp_index" UNIQUE, btree (relname, relnamespace)

Per @wildplasser’s comment, you can omit the name when creating the index, and PG will assign a unique name automatically.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)