Conditional uniqueness constraints
See original GitHub issueProblem
I would like to be able to define a uniqueness constraint that has conditional elements to it so that it can map to and align with a conditional unique index/constraint within the database.
Suggested solution
Modify the @@unique
modifier to include a where: { }
argument that could define the condition that allows this to be unique.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:57
- Comments:18 (2 by maintainers)
Top Results From Across the Web
conditional unique constraint - sql - Stack Overflow
I have a situation where i need to enforce a unique constraint on a set of columns, but only for one value of...
Read more >Conditional Unique Constraint - MSDN - Microsoft
I want to introduce a unique constraint on email but only when a particular setting in a different table is set to true....
Read more >postgresql - Adding condition to Unique Constraint
This is effectively pretty much the same as a unique constraint, because such constraints are implemented with unique indexes anyway.
Read more >Name the Relational Violation Part 1: Conditional Uniqueness ...
"I'm seeing more [data] professionals implementing the following type of conditional unique constraints, typically related to the use of 'soft deletes'):.
Read more >Difference between Unique Indexes and Unique Constraints ...
Overview of UNIQUE constraints in SQL Server ... We can ensure unique value in a column of SQL Server. It can be either...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
One example of how this might be used would be a model of phone numbers for a user, where we have a field to determine which one is the primary number:
In postgres, they support unique indexes with conditions. For this example, you’d create the index with:
This is possible within Rails’ ActiveRecord validations, which I’ve used in the past, and something I would derive great value from also getting within Prisma.
Any update on this issue? Very surprised that this is common but unimplemented yet.
This proposal is okay:
or