Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-04-2019 01:38 AM
Hi,
I want to create employee table in Neo4j. I will create a node for each employee with his name, address, phone, email. when I insert each employee data i should get employee id generated in database. It means employee id is also a property of employee node which is auto generated. Is there a way how to generate integer sequence while creating node in cypher.
11-04-2019 04:58 AM
Does it need to be an auto incremented id, or are you looking for a way to create a primary key for nodes? If the latter perhaps the UUID function in the APOC standard library would help?
https://neo4j.com/docs/labs/apoc/current/graph-updates/uuid/
11-04-2019 11:20 PM
Hi,
I am looking for auto increment id.
Thanks & Regards,
Vijayalakshmi
11-29-2020 09:03 AM
Note: do NOT rely long term stability of a node's internal id. The id of a deleted node can get reused.
11-29-2020 05:16 AM
I think the best was is to use apoc.atomic.add:
1st, create the sequence node:
CREATE (s:Seq {key:"my_seq", value: 0})
Then, use this to get new values:
MATCH (s:Sequence {key:"my_seq"})
CALL apoc.atomic.add(s,'value',1,10)
YIELD newValue as seq
RETURN seq
1 is the number you want to add to your sequence, 10 is how many times to retry if value is locked.
Or you can use the sequence in your query when creating/updating a value, and use the seq as a variable.
return p
All the sessions of the conference are now available online