Can a Neo4j identifier start with an integer?

这一生的挚爱 提交于 2021-02-05 08:29:27

问题


MATCH (p:Product {id:'19134046594'})-[r]-> (o:Attributes {4g:'network'}) return o

I received this exception:

Exception in thread "main" java.lang.RuntimeException: org.neo4j.driver.v1.exceptions.ClientException: Invalid input ':': expected an identifier character, whitespace or '}' (line 1, column 66 (offset: 65))

It's complaining about '4g'. Is '4g' an invalid property key identifier in neo4j? How to work around the issue?


回答1:


You can use the backtick (`) character to quote property names that start with an otherwise illegal character.

For example, this would work:

CREATE (o:Attributes {`4g`: 'network'})
RETURN o;

And this also works:

MATCH (o:Attributes) WHERE o.`4g` = 'network'
RETURN o;



回答2:


According to the naming rules section of the documentation, names you use (which does include property keys):

Must begin with an alphabetic letter.

and

Can contain numbers, but not as the first character.

You can however start it off with an underscore, so _4g:'network' would work.

I'm guessing this is just for example purposes, but it does seem to me that it would be better the other way around: network:'4g'.



来源:https://stackoverflow.com/questions/50012666/can-a-neo4j-identifier-start-with-an-integer

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