Neo4j - convert node attribute storage from string to number?

走远了吗. 提交于 2019-12-14 02:53:36

问题


I have a Neo4j database that was initially created from a Perl script using the Rest::Neo4p Perl module. For some unknown reason, one of the attributes on the nodes was created as a string, even though the values for said attribute on all of the nodes are numeric (verified through a Cypher regex search of that attribute).

Is there an easy way to convert the attribute's storage type from string to a number short of recreating the database? Perhaps a Cypher query that would create a new attribute of numeric type using the value from the textual attribute?

Thanks,

Chris


回答1:


I am not sure how (and if) you can do that with Cypher, but you could convert the attributes using Gremlin:

g.V.sideEffect { it.my_property_name = Integer.parseInt(it.my_property_name) }.iterate()

You can also use a Java extension or just load the DB in embedded mode and convert using Java traversals.



来源:https://stackoverflow.com/questions/21314048/neo4j-convert-node-attribute-storage-from-string-to-number

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