如何在 Neo4J 中创建涉及多个属性的唯一约束 [英] How to create unique constraint involving multiple properties in Neo4J
问题描述
我知道我可以使用 Cypher 在单个属性上创建唯一约束,例如 CREATE CONSTRAINT ON (p:Person) ASSERT p.name IS UNIQUE
.但我想知道是否可以创建一个涉及多个属性的唯一约束.如果是,怎么办?
I know I can create a unique constraint on a single property with Cypher like CREATE CONSTRAINT ON (p:Person) ASSERT p.name IS UNIQUE
. But I was wondering whether it is possible to create a unique constraint which involves multiple properties. If so, how?
推荐答案
neo4j (2.0.1) 目前不支持同时覆盖多个属性的唯一性约束.
neo4j (2.0.1) does not currently support a uniqueness constraint that covers multiple properties simultaneously.
但是,根据您的用例,我可以想到一种可能可以接受的解决方法.假设您希望属性 a、b 和 c 作为一个组是唯一的.您可以添加一个额外的属性 d,它连接 a、b 和 c 的字符串化值,使用适当的分隔符分隔子字符串(例如,a/b 分隔符是一个永远不会出现的字符)在 a 或 b).然后,您可以在 d 上创建唯一性约束.
However, I can think of a workaround that might be acceptable, depending on your use cases. Let's say you want properties a, b, and c to be unique as a group. You can add an extra property, d, that concatenates the stringified values of a, b, and c, using appropriate delimiter(s) to separate the substrings (such that, for example, the a/b delimiter is a character that never appears in a or b). You can then create a uniqueness constraint on d.
[更新]
Neo4j 3.3 添加了对涵盖多个属性的唯一性约束的支持,通过 节点键约束.但是,此功能仅在企业版中可用.
Neo4j 3.3 added support for uniqueness constraints that cover multiple properties, via node key constraints. However, this feature is only available in the Enterprise Edition.
这篇关于如何在 Neo4J 中创建涉及多个属性的唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!