【问题标题】:Define a unique index in EdgeDB在 EdgeDB 中定义唯一索引
【发布时间】:2020-07-27 10:46:35
【问题描述】:
如何在 EdgeDB 中定义唯一索引?
对于简单的属性,您可以添加 constraint exclusive,它会隐式创建唯一索引。
required property name -> str {
constraint exclusive;
}
但是,您不能将constraint exclusive 添加到明确定义的索引中。如何将这样的索引标记为唯一?
【问题讨论】:
标签:
indexing
unique-index
edgedb
【解决方案1】:
您可以将constraint exclusive on (...) 添加到包含类型,其中... 是任意标量表达式。为了保证多个属性的唯一性,应该是一个元组(x, y):
type User {
property first_name -> str;
property last_name -> str;
constraint exclusive on ((.first_name, .last_name));
}
独占约束隐式创建索引。
source