I have a many-to-many join table in Postgres that I would like to index to A) increase performance (obviously) and B) enforce uniqueness. For example:
a_id |
In addition to using the PRIMARY KEY and UNIQUE syntax as explained by @Michael Buen, you can also create an explicit index:
PRIMARY KEY
UNIQUE
CREATE UNIQUE INDEX foo_a_b ON tbl(a_id, b_id);
This is just a normal, multi-column b-tree index (which is exactly what the KEY syntax creates implicitly).