开发者

PostgreSQL unique indexes and string case

开发者 https://www.devze.com 2023-01-24 13:03 出处:网络
If I create a PostgreSQL unique index on a 开发者_Python百科field, is the comparison case-insensitive by default?

If I create a PostgreSQL unique index on a 开发者_Python百科field, is the comparison case-insensitive by default?

If not, is it possible to ask PostgreSQL to ignore string case?


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


CREATE UNIQUE INDEX ux_table_field ON mytable(UPPER(field))


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

0

精彩评论

暂无评论...
验证码 换一张
取 消