2

I'm writing a python 3.6 application that uses Neo4j as a backend with the official python driver. I'm new to Neo4j and Cypher. Data coming into the database needs to replace previous 'versions' of that data. I'm attempting to do this by creating a root node, indicating version. Eg.

MATCH (root:root_node)-[*..]->(any_node:) DETACH DELETE root, any_node
CREATE(root:new_root_node)
...
...

... represents all the new data i'm attaching to the new_root_node

The above doesn't work. How do I incorporate DELETE and CREATE statements in one transaction?

Thanks!

James Schinner
  • 1,549
  • 18
  • 28

1 Answers1

2

There's not a problem with DELETE and CREATE statements in a single transaction.

There are two problems here needing fixing.

The first is with (anynode:). The : separates the variable from the node label. If : is present, then the node label must also be present, and because no label is supplied here you're getting an error. To fix this, remove : completely like so: (anynode)

The second problem is with CREATE(root:new_root_node). The problem here is that the root variable is already in scope from your previous MATCH, so you'll need to use a different variable.

Also, your :new_root_node label doesn't seem useful, as any previously created queries for querying data from the root node will need to change to use the new label. I have a feeling you might be misunderstanding something about Neo4j labels, so a quick review of the relevant documentation may be helpful.

InverseFalcon
  • 29,576
  • 4
  • 38
  • 51
  • Thanks for the reply. This code above is an abstraction of my actually code, done to make it readable in a small space. You have validated what i'm trying to do should work. I'm going to go through my code and make sure i haven't made any syntax errors as you mention. – James Schinner Jun 25 '17 at 00:04
  • It may help to run this in the browser, prefixed with `EXPLAIN`. That will let it check for syntax errors, but it won't actually run the query – InverseFalcon Jun 25 '17 at 00:40