Postgres index naming
Reference from satck overflow
1 min readNov 14, 2019
The standard names for indexes in PostgreSQL are:
{tablename}_{columnname(s)}_{suffix}
where the suffix is one of the following:
pkey
for a Primary Key constraintkey
for a Unique constraintexcl
for an Exclusion constraintidx
for any other kind of indexfkey
for a Foreign keycheck
for a Check constraint
Standard suffix for sequences is
seq
for all sequences
Proof of your UNIQUE-constraint:
NOTICE: CREATE TABLE / UNIQUE will create implicit index “example_a_b_key” for table “example”
Demonstration
Create an index
create index my_table_column_a_idx on my_table(column_a);
Create a multicolumn index
create index my_table_column_a_column_b_idx on my_table(column_a, column_b);
Create a unique index
create unique index my_table_column_a_key on my_table(column_a);
Create a multicolumn unique index
create unique index my_table_column_a_column_b_key on my_table(column_a, column_b);