31

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?

Paul Fleming
  • 23,638
  • 8
  • 74
  • 112
Simone Carletti
  • 168,884
  • 43
  • 353
  • 360

3 Answers3

44

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

Kuberchaun
  • 27,671
  • 6
  • 47
  • 57
2
CREATE UNIQUE INDEX ux_table_field ON mytable(UPPER(field))
Quassnoi
  • 398,504
  • 89
  • 603
  • 604
0

you should be able to create a function based index. (use the UPPER of the field)

Paul Fleming
  • 23,638
  • 8
  • 74
  • 112
Randy
  • 16,268
  • 1
  • 35
  • 53