# Merge nodes by a variable string, not a constant string

**URL:** <https://community.neo4j.com/t/merge-nodes-by-a-variable-string-not-a-constant-string/32494>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [January 22, 2021, 6:20am UTC](https://community.neo4j.com/t/merge-nodes-by-a-variable-string-not-a-constant-string/32494 "2021-01-22T06:20:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiayuforfree](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jiayuforfree/32/16309_2.png) [@jiayuforfree](https://community.neo4j.com/u/jiayuforfree)\
**Post date:** [January 22, 2021, 6:20am UTC](https://community.neo4j.com/t/merge-nodes-by-a-variable-string-not-a-constant-string/32494/1 "2021-01-22T06:20:48Z")

</div>

This works fine:

```auto
merge (s:subject{name:sub})
merge (o:object{name:obj})
merge (s)-[:pre]->(o)

```

however, I want change relationship between s and o by another like this:

```auto
load csv with headers
from 'file:///knowledge_triple.csv'
as line
with line.Subject as sub, line.Predicate as pre, line.Object as obj
merge (s:subject{name:sub})
merge (o:object{name:obj})
merge (s)-[pre]->(o)

```

this cannot be correct, I wonder if it's possiable. 3q

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [January 22, 2021, 8:00am UTC](https://community.neo4j.com/t/merge-nodes-by-a-variable-string-not-a-constant-string/32494/2 "2021-01-22T08:00:49Z")

</div>

```auto
Try this:

CALL apoc.create.relationship(s, pre,{}, o) YIELD rel
REMOVE rel.noOp

// REMOVE rel.noOp is a dummy script as we have to have a return value.

```

---

<div class="post-metadata">

**Author:** ![clem](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/clem/32/4364_2.png) [@clem](https://community.neo4j.com/u/clem)\
**Post date:** [January 22, 2021, 5:18pm UTC](https://community.neo4j.com/t/merge-nodes-by-a-variable-string-not-a-constant-string/32494/3 "2021-01-22T17:18:43Z")

</div>

I'm not clear what your question is, but I do believe you have a typo. There is a missing colon before the label `pre`

`merge (s)-[pre]->(o)`

should

`merge (s)-[:pre]->(o)`

I do recommend the style guide of using all uppercase for Labels as it makes it easier to detect see these errors:

`merge (s)-[:PRE]->(o)`

---

<div class="post-metadata">

**Author:** ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)\
**Post date:** [February 2, 2021, 4:14am UTC](https://community.neo4j.com/t/merge-nodes-by-a-variable-string-not-a-constant-string/32494/4 "2021-02-02T04:14:15Z")

</div>

In this particular case, I think what they were asking for was a way to create the type of the relationship dynamically (from a variable, parameter, or other derived value), so the lack of the colon for the type was intended here (though good eyes, these typos are common).

And dynamic relationship type isn't supported in Cypher (nor is dynamic node labeling), so APOC procs would be the workaround, as ameyasoft provided.
