How to add infinity, NaN, or null values to a double[] property on a node in Cypher/Neo4j

独自空忆成欢 提交于 2019-12-13 00:41:55

问题


I have some nodes in my neo4j graph that are a combination of multiple entities. On these nodes I have a property named "p_value" that has a type of double[].

I'm merging new entities into existing nodes and with my merge command I'm using on match to push the new p_values onto the end of this double[] array. The issues is that for some of my entities I don't have p_values, so I need to push something like -infinity/infinity, NaN, or NULL into my double[] p_value array.

Here is an example cypher query I've tried.

MERGE (process:GOTERM { name: "immune system process", go_id: 50896})
ON CREATE SET process.som = ["som_mouse_3_2"], process.p_value = [NULL]
ON MATCH SET process.som = process.som + "som_mouse_3_2", process.p_value = process.p_value + NULL;

The issue here is that if I have an existing node with that "name" and "go_id" the p_value property will be deleted when I try to add a NULL value to the existing array of p_values.


回答1:


Do you actually want to have a null value in the array or would it be better to just not touch it in the null case?

How about something like this where you only set p_value if the newPValue is non null?

WITH null AS newPValue
MERGE (process:GOTERM { name: "immune system process", go_id: 50896})
ON CREATE SET process.som = ["som_mouse_3_2"], process.p_value = []
ON MATCH SET process.som = process.som + "som_mouse_3_2", 
             process.p_value = CASE WHEN newPValue is null THEN process.p_value ELSE process.p_value + newPValue END
RETURN process


来源:https://stackoverflow.com/questions/26980830/how-to-add-infinity-nan-or-null-values-to-a-double-property-on-a-node-in-cyp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!