Suppose that for certain nodes, attributes have unique constraints defined on them.
When cloning nodes, we copy properties from original to cloned node and then modify the unique attributes on the cloned node.
However, neo4j exhibits eager constraint evaluation and seems to fail as soon as unique properties are replicated from original to cloned node.
Is there are way to differ the constraint evaluation to the end of the transaction?
Or some workaround that can mitigate the problem for the timebeing.
Sample cypher for illustrating the problem:
Create unique constraint for nodes labelled y on attribute id.
create constraint on (y:y) assert y.id is unique;
Create a few y nodes.
create (y:y{id: 1}) return y; create (y:y{id: 2}) return y;
Now, try to clone the y node with the largest id, and assign new ids.
match (y:y) with max(y.id) as maxid match (lasty:y{id: maxid}) unwind range(1, 10) as i create (nexty:y) set nexty = lasty set nexty.id = maxid + i return nexty;
The above cypher fails fast with the below error:
Node 5368657 already exists with label y and property "id"=[2]