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.

Changing property type from string to array

I’m trying to change the property type of a node (from string to array):
match(d:Diagnosis) set d.diagnosis_tool = [d.diagnosis_tool] return d
but it its throwing this error:
Neo.ClientError.Statement.TypeError: Property values can only be of primitive types or arrays thereof
I don’t think it likes that the array only has one element, any ideas on how to achieve this?

1 ACCEPTED SOLUTION

Arrays cannot contain arrays - the message could perhaps be worded more clearly but it seems that in this particular case diagnosis_tool is already an array, and you're trying to create a nested array.

Example:

neo4j> create (d:Diagnosis) SET d.diagnosis_tool=[[1]] RETURN d;
Property values can only be of primitive types or arrays thereof

To limit your query to only those that are currently strings and not arrays, you might do something like this:

match (d:Diagnosis) where d.diagnosis_tool + '' = d.diagnosis_tool 
WITH d as hasStringDiagnosisTool
SET d.diagnosis_tool = [hasStringDiagnosisTool.diagnosis_tool]
RETURN count(d);

View solution in original post

1 REPLY 1

Arrays cannot contain arrays - the message could perhaps be worded more clearly but it seems that in this particular case diagnosis_tool is already an array, and you're trying to create a nested array.

Example:

neo4j> create (d:Diagnosis) SET d.diagnosis_tool=[[1]] RETURN d;
Property values can only be of primitive types or arrays thereof

To limit your query to only those that are currently strings and not arrays, you might do something like this:

match (d:Diagnosis) where d.diagnosis_tool + '' = d.diagnosis_tool 
WITH d as hasStringDiagnosisTool
SET d.diagnosis_tool = [hasStringDiagnosisTool.diagnosis_tool]
RETURN count(d);