If I create a PostgreSQL unique index on a field, is the comparison case-insensitive by default?
If not, is it possible to ask PostgreSQL to ignore string case?
A unique index guarantees that the table won't have more than one row with the same value. It's advantageous to create unique indexes for two reasons: data integrity and performance. Lookups on a unique index are generally very fast.
Yes, absolutely. A unique constraint creates a unique index.
A unique index ensures that the values in the index key columns are unique. A unique constraint also guarantees that no duplicate values can be inserted into the column(s) on which the constraint is created. When a unique constraint is created a corresponding unique index is automatically created on the column(s).
PostgreSQL is case sensitive. To do what you want create a function index. So say
CREATE UNIQUE INDEX test_upper_idx ON mytable (UPPER(myfield));
That way when you use UPPER(myfield)
in your query the index will be used.
See this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With