Cypher - Remove all properties with a particular value

自作多情 提交于 2019-12-10 16:59:37

问题


I'm searching for a way to remove every property, of any node in the DB, having a specific value using Cypher.

Context
I got a csv bulk file from a relational table with plenty of NULL values. LOAD CSV brings them as values. Removing them (replacing them with empty '' within the csv file) resulted in the same issue (properties without values). Tried many (many) Cypher operations to discard NULL values but nothing worked.

Can't find anything in the docs neither by Googling. Can this be done using only Cypher? It seems to me not (yet) supported.

Thanks.


回答1:


How about this (when you know the property-names):

MATCH (n:Label)
WHERE n.property = ''
REMOVE n.property;

MATCH (u:User) 
WHERE u.age = '' 
SET u.age = null;

If you know which columns these are in your import you can do something like this

load csv with headers from "" as line
with line, case line.foo when '' then null else line.foo end as foo
create (:User {name:line.name, foo:foo})

It won't create the properties with null.

For numeric values it's easier as toInt() and toFloat() return null on unparseable values like ''.




回答2:


No, there is no way to do this only with chypher. I suppose that you have already seen the way to do it via REST. That is the best solution for now.



来源:https://stackoverflow.com/questions/24487418/cypher-remove-all-properties-with-a-particular-value

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