This is more of a theoretical question, but because of the way I'm doing things I think it may be relevant. Right now I've added a constraint on User.uuid, and when a user creates their account I'm adding a uuid property manually with apoc.create.uuid(). I know I can install it to the label, but I need that uuid returned from the query that created the user, so that doesn't work. My question is would it throw a constraint error because it might not be checking its uniqueness? I know it would be unlikely if possible, but I'd rather go with a solution where that won't happen
Hello @pererasys and welcome to the Neo4j community,
Yeah it will throw a constraint error if you of course created the unique constraint:)
Yea, I assumed so. Do you know of any way to create a new node with a unique uuid that can be accessed at creation? Because of the way the apoc plugin generates the uuid's, they aren't available until after the query is completed.
Try something like
SET p.pid = apoc.create.uuid() RETURN pid
If it's not working and you don't need to use the id for somthing else and you accept that the id will be reused when you will delete a node, you can do like this:
SET p.pid = id(p) RETURN pid
Your first suggestion is what I'm currently doing, but this is what will throw the constraint error, and I can't use the node id because I'm using these id's across other databases. Is there no recommended solution for unique id's? Unless apoc.create.uuid() creates a unique value for the whole database as opposed to the label, in which case it should never throw a constraint error.
You can manage ids by yourself and create a cypher request that will return you an unused id