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.

Convert property and all values to string inside graph db

Hello.

I have an existing graph database and a property that is a number. I realized after I created the database that I need that as a string. I can fix the code for new inserts but how do I convert, en mass, the existing data?

Thanks.
Rhys

1 ACCEPTED SOLUTION

If your data set is small, you might be able to get by with something like:

MATCH (n:Label) 
SET n.property = toString(n.property)

However if your dataset is large and you can't sustain that in a single transaction, then the apoc.periodic.iterate would likely be of use to you. Modify the following. The first argument to the function to limit to exactly the smallest set that you can. The second argument to perform the mutation. The 3rd argument controls the batch size and concurrency of the overall operation.

CALL apoc.periodic.iterate(
  "MATCH (n:Label)
   RETURN n",
  "SET n.property = toString(n.property)"
  {batchSize:1000, iterateList: true, parallel: true, concurrency: 4}
);

View solution in original post

1 REPLY 1

If your data set is small, you might be able to get by with something like:

MATCH (n:Label) 
SET n.property = toString(n.property)

However if your dataset is large and you can't sustain that in a single transaction, then the apoc.periodic.iterate would likely be of use to you. Modify the following. The first argument to the function to limit to exactly the smallest set that you can. The second argument to perform the mutation. The 3rd argument controls the batch size and concurrency of the overall operation.

CALL apoc.periodic.iterate(
  "MATCH (n:Label)
   RETURN n",
  "SET n.property = toString(n.property)"
  {batchSize:1000, iterateList: true, parallel: true, concurrency: 4}
);