Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis Graph: Merge on existing nodes

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.

like image 329
Rikard Olsson Avatar asked Jun 20 '19 11:06

Rikard Olsson


Video Answer


1 Answers

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.

like image 197
Rawhi Avatar answered Oct 17 '22 13:10

Rawhi