如何在 SQLite 中创建不区分大小写的唯一列

How to make a case-insensitive unique column in SQLite(如何在 SQLite 中创建不区分大小写的唯一列)
本文介绍了如何在 SQLite 中创建不区分大小写的唯一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直无法找到这个问题的答案.我正在尝试创建一个具有唯一电子邮件地址列的表.当我这样做时

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 TEXT PRIMARY KEY,
  password TEXT NOT NULL CHECK(password<>''),
  UNIQUE (lower(email))
)

使用 PDO 时出现错误:

when using PDO, I get the error:

致命错误:未捕获的异常 'PDOException' 带有消息 'SQLSTATE[HY000]:一般错误:1 靠近(":script.php:65 中的语法错误'堆栈跟踪:#0 script.php(65):PDO->exec('CREATE TABLE us...') #1 {main} 在第 65 行的 script.php 中抛出

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 near "(": syntax error' in script.php:65 Stack trace: #0 script.php(65): PDO->exec('CREATE TABLE us...') #1 {main} thrown in script.php on line 65

第 65 行是 CREATE TABLE 行.如果我取出 UNIQUE,它工作正常.有更好的方法吗?

Line 65 is the CREATE TABLE line. If I take out the UNIQUE, it works fine. Is there a better way of doing it?

推荐答案

COLLATE NOCASE 是你的朋友:

COLLATE NOCASE is your friend:

CREATE TABLE users (
  email TEXT PRIMARY KEY,
  password TEXT NOT NULL CHECK(password<>''),
  UNIQUE (email COLLATE NOCASE)
)

这篇关于如何在 SQLite 中创建不区分大小写的唯一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

FastAPI + Tortoise ORM + FastAPI Users (Python) - Relationship - Many To Many(FastAPI+Tortoise ORM+FastAPI用户(Python)-关系-多对多)
php 5.x 7.x, ssl pdo error: Peer certificate CN=`someNameamp;#39; did not match expected CN=amp;#39;someIPamp;#39;(PHP 5.x 7.x,SSLPDO错误:对等证书CN=`ome Nameamp;#39;与预期的CN=amp;#39;ome IPamp;#39;不匹配)
Window functions not working in pd.read_sql; Its shows error(窗口函数在pd.read_sql中不起作用;它显示错误)
(Closed) Leaflet.js: How I can Do Editing Geometry On Specific Object I Select Only?((已关闭)Leaflet.js:如何仅在我选择的特定对象上编辑几何图形?)
in sqlite update trigger with multiple if/Case Conditions(在具有多个IF/CASE条件的SQLite UPDATE触发器中)
Android: Why is Room so slow?(Android:为什么Room这么慢?)