cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Aborting a transation from Cypher

mburbidg1
Node Clone

Is it possible to force a transaction to fail within the Cypher query itself.

The use case is a write transaction that makes some changes to the graph and then at the end of the query uses apoc.nodes.cycles to check to see if any cycles were introduced. If so, then I'd like to fail the transaction.

Michael-

3 REPLIES 3

I don't believe so in Neo4j Browser, as it uses implicit transactions, which are auto-close. I don't know of a command to rollback the changes. 

The cypher-shell uses explicit transactions, where you have to manage the transactions. You could either commit or rollback the changes based on your outcome. 

https://neo4j.com/docs/cypher-manual/current/introduction/transactions/

You can abort a cypher statement by using apoc.util.validate within the statement.

apoc.util.validate - APOC Documentation (neo4j.com)

anthapu
Graph Fellow

You can try MERGE statement with null value.

MERGE (n:StopExecution {id: $not_a_valid_param})

This will throw an exception and aborts the transaction as you cannot do a MERGE with null values.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online