Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a unique index in EdgeDB

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?

like image 495
CodesInChaos Avatar asked May 22 '26 21:05

CodesInChaos


1 Answers

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

like image 114
CodesInChaos Avatar answered May 25 '26 23:05

CodesInChaos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!