Postgres hash index with unique constraint
The documentation leaves no room for doubt:
Currently, only B-tree indexes can be declared unique.
There was a discussion on the hackers list about this recently, and it was concluded that it wouldn't be simple to add the capability to allow UNIQUE
hash indexes.
You can achieve this using an exclusion constraint:
create table t (id int);create index i on t using hash (id);alter table t add constraint c exclude using hash (id with =);