Mark Needham

Thoughts on Software Development

neo4j/cypher: CREATE UNIQUE – “SyntaxException: string matching regex `$’ expected but `p’ found”

with one comment

I’ve been playing around with the mutating cypher syntax of neo4j which allows you to make changes to the graph as well as query it, a feature introduced into cypher in May in release 1.8 M01.

I was trying to make use of the ‘CREATE UNIQUE‘ syntax which allows you to create nodes/relationships if they’re missing but won’t do anything if they already exists.

I had something like the following:

START product1=node:products('product_id:1')
CREATE UNIQUE product1-[:sold]->(sales200010 {type:"product_sales", value: 1, name: "Oct 2000 Sales"})

So I already have a product indexed with a ‘product_id’ of 1 and I wanted to create a relationship to a node defining the sales for that product.

When I tried to execute that query I was ending up with the following error:

SyntaxException: string matching regex `$' expected but `p' found
Think we should have better error message here? Help us by sending this query to
Thank you, the Neo4j Team.

I was a bit puzzled as to why that wouldn’t work but eventually I read the release notes for 1.8 M07 where I learnt that in earlier versions of neo4j ‘CREATE UNIQUE’ had actually been known as ‘RELATE’ instead.

Since I’m using 1.8 M06 at the moment I just needed to change ‘CREATE UNIQUE’ to ‘RELATE’ but RC1 is now available so I’ll soon switch to that and go back to ‘CREATE UNIQUE’ again.

Be Sociable, Share!

Written by Mark Needham

September 9th, 2012 at 10:29 pm

Posted in neo4j

Tagged with ,

  • Coolio,
    let us know any feedback you have Mark, much apprciated. And keep up that blogging 🙂