How do you define a unique index in EdgeDB?
For simple properties you can add constraint exclusive which implicitly creates a unique index.
required property name -> str {
constraint exclusive;
}
However you can't add constraint exclusive to an explicitly defined index. How do you mark such an index as unique?
You can add constraint exclusive on (...) to the containing type, where ... is an arbitrary scalar expression. To ensure the uniqueness of multiple properties, it should be a tuple (x, y):
type User {
property first_name -> str;
property last_name -> str;
constraint exclusive on ((.first_name, .last_name));
}
An exclusive constraint implicitly creates an index.
source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With