简体   繁体   English

如何忽略 PostgreSQL 中区分大小写的行

[英]How to ignore case sensitive rows in PostgreSQL

I know this question may duplicate but i really got confused since I'm new to PostgreSQL.我知道这个问题可能会重复,但我真的很困惑,因为我是 PostgreSQL 的新手。 I'm trying to store emails which must not be case sensitive.我正在尝试存储不能区分大小写的电子邮件。 For example Johndoe@gmail.com must be identical with JoHnDoE@gmail.com in PostgreSQL but i can't find any solution.例如Johndoe@gmail.com必须与JoHnDoE@gmail.com中的 JoHnDoE@gmail.com 相同,但我找不到任何解决方案。 I know about lower() function, But i don't want use it.我知道lower() function,但我不想使用它。

Any solution?有什么解决办法吗? Or this is not possible at all in PostgreSQL?或者这在 PostgreSQL 中根本不可能? I'm using pgAdmin 4我正在使用 pgAdmin 4

Use Non deterministic collation (only PostgreSQL version >= 12):使用非确定性排序规则(仅 PostgreSQL 版本 >= 12):

From https://dba.stackexchange.com/questions/101294/how-to-create-postgres-db-with-case-insensitive-collation :https://dba.stackexchange.com/questions/101294/how-to-create-postgres-db-with-case-insensitive-collation

CREATE COLLATION ndcoll (provider = icu, locale = 'und', deterministic = false);
CREATE COLLATION case_insensitive (provider = icu, locale = 'und-u-ks-level2', deterministic = false);
CREATE COLLATION ignore_accents (provider = icu, locale = 'und-u-ks-level1-kc-true', deterministic = false);

Edit编辑

From https://stackoverflow.com/a/59101567/2928168 :https://stackoverflow.com/a/59101567/2928168

    CREATE COLLATION case_insensitive (
      provider = icu,
      locale = 'und-u-ks-level2',
      deterministic = false
    );

    CREATE TABLE names(
      first_name text,
      /* Example collation used in schema directly */
      last_name text COLLATE "case_insensitive",
    );

    insert into names values
      ('Anton','Egger'),
      ('Berta','egger'),
      ('Conrad','Egger');

    select * from names
      order by
        last_name,
        /* Example collation used only in some query */
        first_name collate case_insensitive;

Useupper() in both members of the comparison.在比较的两个成员中使用upper()

Use ILIKE operator (or its equivalent ~~* for ILIKE and !~~* for NOT ILIKE ).使用ILIKE运算符(或等效的~~*用于ILIKE!~~*用于NOT ILIKE )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM