Skip to content

Defining composite and unique indexes #1608

Answered by elprans
CodesInChaos asked this question in Q&A
Discussion options

You must be logged in to vote

but I couldn't find a way to reference multiple properties in an index.

Use a tuple, like this:

type User {
    property first_name -> str;
    property last_name -> str;
    index on ((.first_name, .last_name));
}

You can use any (scalar) expression inside the parentheses, actually.

However you can't add constraint exclusive to an explicitly defined index. How do you mark such an index as unique?

Recent nighlies have the ability to define constraints on types:

type User {
    property first_name -> str;
    property last_name -> str;
    constraint exclusive on ((.first_name, .last_name));
}

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@elprans
Comment options

@CodesInChaos
Comment options

@elprans
Comment options

@CodesInChaos
Comment options

@elprans
Comment options

Answer selected by CodesInChaos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants