Redis Graph: Merge on existing nodes
Asked Answered
D

1

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.

Dovetailed answered 20/6, 2019 at 11:28 Comment(0)
T
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.

Tiffin answered 24/6, 2019 at 9:33 Comment(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 #55681183, who's also running separate commands but in some MULTI query thingy.Dovetailed

© 2022 - 2024 — McMap. All rights reserved.