How to make a case-insensitive unique column in SQLite

后端 未结 2 1379
情书的邮戳
情书的邮戳 2021-01-13 08:37

I haven\'t been able to find the answer to this. I\'m trying to create a table with a unique email address column. And when I do

CREATE TABLE users (
  email         


        
相关标签:
2条回答
  • 2021-01-13 09:10

    COLLATE NOCASE is your friend:

    CREATE TABLE users (
      email TEXT PRIMARY KEY,
      password TEXT NOT NULL CHECK(password<>''),
      UNIQUE (email COLLATE NOCASE)
    )
    
    0 讨论(0)
  • 2021-01-13 09:12

    For speed, make all your input lower case first, and use a normal unique column.

    This is great for read-more-frequent-than-write use cases because queries just need to compare strings, rather than converting the field first which it must do lots of times to compare.

    0 讨论(0)
提交回复
热议问题