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
Feature Request: Unique constraint across multiple labels #7814
Comments
Would make it easier, but at the moment you could create a common label D for all nodes and create the constraint on that. |
Hi @spacecowboy, i was re-directed to this from stack overflow as a top search on Google. Many thanks, Nick. |
Ideally you can do this from the start. So that when you create nodes in the first place, they have the correct labels. Say I have two kinds of labels originally, A create query then looks something like this
and
Both In case you need to update an existing graph, you can set new labels on nodes in this way for example:
and naturally
|
Is there a real-life use case for a multi-label constraint, which could be shared with others? |
The use case is the same as for any other unique constraint. The question is, do you want to create the super type D (referring to the comment of spacecowboy ) or not? In my case, you would add the label D to tens of thousands of nodes, which would not be used in any query afterwards. This makes the database more complex than it should be. |
I vote up the need for this. |
I had like to use a constrain related to uuid's across several labels. |
I don't know if that's the same or not.
with I want to have a constrain that says only one employee in one each company can have |
Any news about this topic ? Is there chance to get a functions to add constraint for multiple labels ? |
I arrived here because I want to use node ID to simplify operations (e.g., "connect ID X to ID Y" regardless of labels), but then I see the warning here stating:
Fine - but then why can't I generate a unique constraint which either A) spans multiple labels (i.e., this issue), or B) for all nodes (does not require a label)? Now I am required to create a uuid for each label, or a supertype for all labels. |
I've started with Neo4j yesterday and already ran into this issue. It would be very useful to add a constraint on a combination of 2 or more labels. |
Hey, I'm bumping this up as well
Basically, a lot of Yes we can add a label that is I would love to be able to add constraints to label combos. Right now we are handling it by being very careful with our ingests and making sure we don't end up with duplicates, but that's not the best... |
Hello everyone. Let me give a (much delayed) update on this topic. There are no concrete plans to prioritise this work currently, although multi-label constraints are recognised as something that would be useful and something that we would like to investigate in more detail at some point. For now, the suggestion from @spacecowboy is the way to work around this issue. Let me also comment on some specific things below. Uniqueness across entity types A comment on the requirement to have unique UUID across all different entities in the database. In most cases the required uniqueness applies to each type specifically and not across the types, even if they use the same property. E.g. Now, there are of course cases where the uniqueness constraint applies across labels, e.g, we have
What you are referring to we could call "neighbourhood constraints", "node centric constraints", "local constraints" or similar, and although it is an interesting topic it is different from what this issue is about.
If you have a property that needs to be unique across all of those different type of nodes, then currently there is no other way than to give them a common label. Since you need to get all of the services separately I would refactor them into their own nodes instead of inlining them into each specific account, repository, etc. This will make your modell cleaner and easier to work with I think. Something like:
Getting all of your services is now as simple as
and getting, e.g, all twitter accounts
You can find more modelling tips here https://neo4j.com/docs/getting-started/current/data-modeling/ |
I have a set of nodes with multiple Labels (A, B, C). All nodes have a common property, which is unique across all labels. However, when creating unique constraint it is limited to one label, isn't it?
Documentation says something like:
CREATE CONSTRAINT ON (n:A) ASSERT n.uid IS UNIQUE
But it would be useful to do something like this:
CREATE CONSTRAINT ON (n:A AND n:B AND n:C) ASSERT n.uid IS UNIQUE
or
CREATE CONSTRAINT ON (n) ASSERT n.uid IS UNIQUE
The text was updated successfully, but these errors were encountered: