Paolo Di Pietro
Paolo Di Pietro

Reputation: 529

Probable bug in Neo4j cypher

I'm running Neo4j 2.0.0 community edition.

I'm in trouble running a query. I believe to have discovered a flaw about labels.

Here are a query with 3 sligthly different sintax, all returning an error. I'm trying to create an element with 2 labels:

Invalid input ':': expected an identifier character, whitespace, '|', a length specification, a property map or ']' (line 1, column 87)
"MATCH ( from {uuid:'set'}),( to {uuid:'model element'})   CREATE from-[r :HasAttribute:ModelElement { Name : 'model element' , cardinality : '0::*' , Type : 'model element' }]->to Return r;"


Invalid input ':': expected an identifier character, whitespace, '|', a length specification, a property map or ']' (line 1, column 86)
"MATCH ( from {uuid:'set'}),( to {uuid:'model element'})   CREATE from-[r:HasAttribute:ModelElement { Name : 'model element' , cardinality : '0::*' , Type : 'model element' }]->to Return r;"


Invalid input ':': expected '`', whitespace, '|', a length specification, a property map or ']' (line 1, column 89)
"MATCH ( from {uuid:'set'}),( to {uuid:'model element'})   CREATE from-[r:`Has_Attribute`:`Model_Element` { Name : 'model element' , cardinality : '0::*' , Type : 'model element' }]->to Return r;"

The following query runs, but the result is obviously not correct, because I need 2 labels and not a label with a colon (:)

MATCH ( from {uuid:'set'}),( to {uuid:'model element'})   CREATE from-[r:`Has_Attribute:Model_Element` { Name : 'model element' , cardinality : '0::*' , Type : 'model element' }]->to Return r;

Hope someone can help.

Upvotes: 0

Views: 730

Answers (1)

fbiville
fbiville

Reputation: 8950

You are conflating labels (for nodes) and types (for relationships). A node can have 0 to n labels.

A relationship has exactly 1 type.

Both node labels and relationship types are prefixed by ':'.

As a rule of thumb, it is recommended to write labels as capitalized and relationship types in upper case, thus achieving a better readability.

Source :

Upvotes: 4

Related Questions