7

Imagine that two nodes, (:USER {name: "John"}) and (:AGE {name: "28"}), exist. Now, the following query is ok with Neo4j

MATCH (u:USER {name: "John"})
MATCH (a:AGE {name: "28"})
MERGE (u)-[:IS]->(a)

and creates the IS relationship between the two nodes. When the same query is run on Redis Graph, I get the following error: Syntax error at offset 22 near 'MERGE'. Does anyone know how to run the same query on Redis Graph?

I should add that CREATE does not work instead of MERGE since it will create a duplicate of an (possibly) already existing edge.

Rikard Olsson
  • 841
  • 1
  • 7
  • 28

1 Answers1

7

Currently, MERGE only functions as a standalone clause so it cannot be combined with other directives such as MATCH or RETURN.

Reference: Merge command, GitHub issue

You can do something like this (but it will create the whole pattern instead):

MERGE (u:USER {name: "John"})-[:IS]->(a:AGE {name: "28"})

So I think the only option for now is to perform two separate commands:

MATCH (u:USER {name: "John"})-[r:IS]->(a:AGE {name: "28"})
RETURN count(r)

If this transaction return empty result then you need to create the relationship:

MATCH (u:USER {name: "John"})
MATCH (a:AGE {name: "28"})
CREATE (u)-[:IS]->(a)

Edit: After 20-06-2020, this answer is not relevant since they are now support such queries.

Rawhi
  • 6,155
  • 8
  • 36
  • 57
  • 1
    Thanks for your answer @Rawhi. Yeah, right now I do separate commands as well and it works ok. However, I just find a duplicate of my question here https://stackoverflow.com/questions/55680683/node-reuse-instead-of-creating-new-ones, who's also running separate commands but in some MULTI query thingy. – Rikard Olsson Jun 24 '19 at 11:39