-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support "unique" constraint on relationships #173
Comments
Could you elaborate on what you mean by unique for relationships. It seems like you have something useful in mind, but I fail to understand exactly what the scope of the uniqueness should be. Should there only be one relationship with label The intent of the specification of Cypher around constraints has been to only provide the syntax for defining constraints, and an understanding of the semantics. Not to define which constraints an implementation should (or should not) support. Coming up with a good understanding of the use case, and then a clear way of expressing it is still very valuable here. |
Unique as in the same source and target node - i.e. what So if someone uses But if someone uses a bare |
Like my comment on #173 the syntax could be simplified to
and the word "ASSERT" isn't really needed either. This is mostly because what I really want is to enforce a strict tree in a graph for a certain relationship label by specifying
|
Ah, now I've read #166 I guess the syntax could be
|
So relationships of another type between the same nodes are fine? This is essentially a cardinality constraint, and could be expressed a bit more generally like this:
|
Nearly, I'm looking for there to be only one link of type R between any pair of nodes. A node may be start or finish of any number of R. So, perhaps:
I'm not that bothered by the syntax though :-) - with this, and #172, I just want to be able to enforce a DAG. |
Ah, yes, you're right. |
Updated the original comment to include the name of the CIR |
I've tried to capture this CIR in #166. |
The example above using
|
How about we start simple (as I started in the beginning :) and just do:
as I'd suggest that covers a large set of the use cases (enforcing a DAG like a pert chart) and it already has a precedent in the To enforce a tree (the remaining set of use cases I think) would need:
I think (i.e. the multiple length and added direction) plus something to enforce a unique root - but I'd be happy to leave that out of this discussion. If someone wants to make a case for the general "size" form then perhaps do so in a different ticket. |
I am also looking for something similar. I would like a unique constraint on relationship properties. For example, I create the graph incrementally (say in batches from Kafka by repeatedly applying the below operation for every batch):
The above will create duplicates and I understand that I could use For my use case, I actually don't want neo4j to do anything if the "same relationship" (as defined by the uniqueness constraint below) already exists or even better throw an exception so the application can use that info to do something else. This way the double locking can be avoided and I can finally build the graph incrementally as fast as possible.
|
CIR-2017-173
Related to #172
There are some graphs where you want to ensure there are no duplicate relationships.
http://neo4j.com/docs/developer-manual/current/cypher/clauses/create-unique/ does exist but that requires all developers to remember to do it!
It would be great to be able to say
and have cypher throw an error if a duplicate is attempted.
The text was updated successfully, but these errors were encountered: