1

I know this question may duplicate but i really got confused since I'm new to PostgreSQL. I'm trying to store emails which must not be case sensitive. For example [email protected] must be identical with [email protected] in PostgreSQL but i can't find any solution. I know about lower() function, But i don't want use it.

Any solution? Or this is not possible at all in PostgreSQL ? I'm using pgAdmin 4

1
  • 1
    "But i don't want use it" - why? Please expand on your use case if you're throwing out perfectly fine options for some reason. Commented Mar 4, 2021 at 22:24

3 Answers 3

3

Use Non deterministic collation (only PostgreSQL version >= 12):

From 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 :

    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;
Sign up to request clarification or add additional context in comments.

5 Comments

But how to enable it for specific column? like as i said, "email" field. Explain please
Added example .
Thanks for your help. Appreciate
How to combine both of them (unaccent + case insensitive) and which index to use for both sided LIKE queries, please? thanks!
@Lunack Your question is different than the posted here, as the author wanted to declare the field this way, not only use it in a comparison. You should ask a new question.
0

Use upper() in both members of the comparison.

1 Comment

I don't want use function at all but thanks.
0

Use ILIKE operator (or its equivalent ~~* for ILIKE and !~~* for NOT ILIKE).

7 Comments

I don't want use function at all but thanks
This is not a function.
If you post an example of the query you are trying to use, I can make an example with it.
Yes but i mean " Is there any data type like MySQL " which ignore case sensitive ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.