cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Two question

for Neo4j enterprise :

  1. How to automatic generate id ?
  2. How to make general Uniqe constraints ?
1 ACCEPTED SOLUTION

In general we would not recommend using a Cypher solution to implement a sequence id, as you'd likely run into race conditions against concurrently running queries. We'd recommend sticking with a UUID instead.

Keep in mind that one huge case for sequence IDs in SQL is as foreign keys between tables to relate entries to each other, and this isn't needed in Neo4j as we use relationships instead, which are not dependent upon these (they are dependent upon the graph ids Neo4j automatically assigns to nodes, but these are not guaranteed to be sequential, as they can be reused after node deletion, and that same characteristic can make them a bad fit for saving outside of Neo4j as a means of node lookup).

View solution in original post

7 REPLIES 7

thanks you for reply.
apoc.create.uuid() The string is a guid.
Does it create problems for performance?
I must create a unique id number-based?

do you mean sequence number, as a node property for the data ?

Yes. for node propery id

If you want to have integer based number that mimics a row_number for distinct elements you could do something like:

Match (n:User) with n limit 10 with apoc.coll.zip(range(1,length(collect(n))),collect(n)) as pairs unwind pairs as pair return pair

Now you could take pair[0] and set it as a property on pair[1]

In general we would not recommend using a Cypher solution to implement a sequence id, as you'd likely run into race conditions against concurrently running queries. We'd recommend sticking with a UUID instead.

Keep in mind that one huge case for sequence IDs in SQL is as foreign keys between tables to relate entries to each other, and this isn't needed in Neo4j as we use relationships instead, which are not dependent upon these (they are dependent upon the graph ids Neo4j automatically assigns to nodes, but these are not guaranteed to be sequential, as they can be reused after node deletion, and that same characteristic can make them a bad fit for saving outside of Neo4j as a means of node lookup).

thanks you.
i am trying to learn new