简体   繁体   中英

Cypher using value from WITH in CREATE clause as relationship name

I am new to neo4j and cypher. I am wondering if there is possibility to use value from WITH caluse and use it as reletionship name in CREATE clause like in example below (which obviously creates relationship 'rr' instead of expanding it to 'rr's value).

MATCH (m:Month)-[r:`2`]->(d:Day)
WITH type(r) as rr, d
MATCH (mm:Month)
CREATE UNIQUE (mm)-[:rr]->(d)

I am using Cypher 1.9 and neo4j ver 2.0.0-M03

There's no way to do this. The syntax is ambiguous, so the cypher parser wouldn't be able to tell if you want to use your variable or if you just want to create an :rr relationship type.

Cypher needs a way to use expressions for relationship types. There are some open issues for that feature. It would be nice for parameters as well.

https://github.com/neo4j/neo4j/issues/340

https://github.com/neo4j/neo4j/issues/45

I created an example for you. Your Query works, at least for the small data I set up.

http://console.neo4j.org/?id=eevi7d

Your code works with Cypher 2.0, but it doesn't work with Cypher 1.9 because you are expected to start your query with a START or a CREATE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM