1
votes

I have an edge with sevral properties. I would like to keep the edge but remove only the name property.

My java Cypher is this :

public static final String DELETE_EDGE_PROPERTY_QUERY = //
        "MATCH ()-[r]->() where id(r) = {1} REMOVE r.{2} RETURN r"; //

It works on cypher console but doesn't work on jdbc.

I got this error :

processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [MATCH ()-[r]->() where id(r) = {1} REMOVE r.{2} RETURN r]; SQL state [null]; error code [0]; Some errors occurred : [Neo.ClientError.Statement.SyntaxError]:Invalid input '{': expected an identifier, whitespace, a function name or a property key name (line 1, column 45 (offset: 44)) "MATCH ()-[r]->() where id(r) = {1} REMOVE r.{2} RETURN r" `

Any suggestions?

Thanks

EDIT

I couldn't do with jdbc template. so I have used String replacement: Setting the property to NULL will delete the property (http://www.baeldung.com/java-neo4j)

Solution : Java :

String deleteQuery = String.format(DELETE_EDGE_PROPERTY_QUERY, property);
plantJdbcTemplate.update(deleteQuery, edgeId);

cypher :

public static final String DELETE_EDGE_PROPERTY_QUERY = //
        "MATCH ()-[r]->() where id(r) = {1} SET r.%s = NULL RETURN r";
1
You may need to use the property name like {:id} instead of indexes.RP-
Hey RP, thanks for replying. Are you sure? I want to remove the property itself and not it's value. Example : Edge (name = blabla, date = 1981, degree = 5) Hre I want to remove name and not blablaErEcTuS
I think it should be something like this MATCH ()-[r]->() where id(r) = {:id} REMOVE r.name RETURN rRP-
indeed that' s what I did but here name should also be a param {:name} is passed as a property. I want to be able to remove any property(name, value, degree, age, etc)ErEcTuS
RP, I have finally opted for String replacement and it seems to work. Thanks. I have EDIT my original post to add the solutionErEcTuS

1 Answers

1
votes

This not a neo4j-jdbc issue, it's related to the design of Neo4j about parameterized query.

On a query you can parameterized all data you want, except:

  • labels
  • relationship types
  • properties

If you want to do it in Cypher, there are a lot of helpers in the APOC plugin.