Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create unique CONSTRAINT to relationship by neo4j cypher?

How to create unique CONSTRAINT to relationship by neo4j cypher?

like image 204
Kail Avatar asked May 12 '14 13:05

Kail


2 Answers

If I understood your problem correctly, you want to enforce uniqueness of certain kind of relation rather than uniqueness of relation's certain attribute. If that's what you want, then you enforce such uniqueness by using "CREATE UNIQUE":

MATCH (root { name: 'root' })
CREATE UNIQUE (root)-[:LOVES]-(someone)
RETURN someone

The Neo4j Manual: Create unique relationships

like image 87
ikolomiets Avatar answered Jun 24 '23 04:06

ikolomiets


it seems that a relationship constraint can only enforce the existence of a relationship property but not its uniqueness

CREATE CONSTRAINT ON ()-[like:LIKED]-() ASSERT exists(like.day)

http://neo4j.com/docs/developer-manual/current/cypher/#query-constraints-prop-exist-rels

like image 40
Albert s Avatar answered Jun 24 '23 04:06

Albert s