question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Case insensitive unique constraint

See original GitHub issue

Problem

It’s really important to keep the casing in some of our columns which are unique ( cannot be duplicated ) which constraint can be overridden so easily by just change the casing

Suggested solutions

I’ve found some articles and the most matching one is this Within schema it’d be great having

model Blog {
	...
	name String @unique(mode:"insensitive")
}

Alternatives

The second solution which is the only available at the moment is to create another column with lowercased letters and it’ll be the unique one

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
pantharshit00commented, Oct 5, 2020

This is more likely to be solved by citext support in schema. That will come eventually via https://github.com/prisma/prisma/issues/3447 although since citext is an extension instead of built in postgres type, it can take more time.

After that you could possibiliy do:

model Blog {
  ...
  name String @pg.Citext @unique
}
1reaction
albertoperdomocommented, Feb 1, 2021

@probablycorey Yes, we are adding support Citext as a type. This is scheduled for 2.16.0. I will also update #3447.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create Unqiue case-insensitive constraint on two varchar fields
In Oracle 10g, how do I add a unique case-insensitive constraint on two varchar fields? For example, given the following records already in...
Read more >
How To Make Unique Constraint Case Sensitive In SQL ...
This script creates a case insensitive database and a table in that database that has a case sensitive column with a unique constraint...
Read more >
Case insensitive UNIQUE constraints in Postgres - Sean Huber
Adding UNIQUE constraints to tables in Postgres is very easy! Imagine we have the following table: CREATE TABLE users ( id uuid PRIMARY...
Read more >
How to Create Case-Insensitive Unique Index - Ed Chen Logic
Using unique case-insensitive constraint in a column sometimes is reasonable in business logic to prevent duplicate items.
Read more >
MS-SQL: unique constraint case-insensitive
How do I add a case-insensitive constraint without altering the column collation? I've tried. CONSTRAINT [AK_User_Username_UserType] UNIQUE ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found