# Adding multiple labels when loading from CSV

**URL:** <https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351>\
**Category:** Cypher\
**Created:** [October 10, 2018, 6:35am UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351 "2018-10-10T06:35:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![norbert](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/norbert/32/744_2.png) [@norbert](https://community.neo4j.com/u/norbert)\
**Post date:** [October 10, 2018, 6:35am UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351/1 "2018-10-10T06:35:08Z")

</div>

When using the neo4j-admin tool I can attach multiple labels to a node by using the `:LABELS` column. I want to do something similar with `LOAD CSV` and thought that a statement like:

```auto
LOAD CSV WITH HEADERS FROM "file:///tlpdb/48871/outnew/node-TLPackage.csv" AS row
         MERGE (c:TLPackage { uuid: row.uuid, name: row.name, revision: toInt(row.revision) })
         ON CREATE set c:row.`:LABELS`

```

might work, but that didn't do it. Is there a way to use the labels taken from a column (in my case there is only one additional label there) and add it to the load/merge/on create call?

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [October 10, 2018, 1:53pm UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351/2 "2018-10-10T13:53:56Z")

</div>

standard cypher does not allow for dynamic labels - this is basically what you want with `:LABELS` column.

`CALL apoc.create.addLabels` to the rescue!

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [October 10, 2018, 7:55pm UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351/3 "2018-10-10T19:55:50Z")

</div>

you should only use the uuid for merging (and create an constraint on it).

There is also apoc.merge.node() which allows for dynamic labels too.

---

<div class="post-metadata">

**Author:** ![norbert](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/norbert/32/744_2.png) [@norbert](https://community.neo4j.com/u/norbert)\
**Post date:** [October 11, 2018, 1:13am UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351/4 "2018-10-11T01:13:48Z")

</div>

Hi Stefan, hi Michael,  
thanks for suggestion apoc functions, which I have tried, but it seems that in the `ON CREATE` part of the `MERGE` command calls are not allowed. That would mean I would have to add additional calls after the initial merge to rewrite labels I guess.

Since I have only 6 or so sub-classes (different labels to add) I have changed the approach, split the original data into separate csv files per label, and then just add one cypher merge call for each csv separately.

This is not optimal, because it codes parts of the logic into the cypher code, while having programmatically being able to add labels from CSV columns would be future proof.

Thanks a lot for your suggestions

Norbert

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [October 11, 2018, 1:50pm UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351/5 "2018-10-11T13:50:24Z")

</div>

`apoc.merge.node` allows you to supply two maps: on for identifying properties and another one for the remainder. What are you missing there?

---

<div class="post-metadata">

**Author:** ![norbert](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/norbert/32/744_2.png) [@norbert](https://community.neo4j.com/u/norbert)\
**Post date:** [October 12, 2018, 5:52am UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351/6 "2018-10-12T05:52:08Z")

</div>

`apoc.merge.node` ??? I cannot find this listed on [APOC User Guide 3.3.0.4](https://neo4j-contrib.github.io/neo4j-apoc-procedures/index33.html#_overview_of_apoc_procedures_functions) which according to [GitHub - neo4j-contrib/neo4j-apoc-procedures: Awesome Procedures On Cypher for Neo4j - codenamed "apoc" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If you like it, please ★ above ⇧&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;](https://github.com/neo4j-contrib/neo4j-apoc-procedures)

> All included procedures are listed in the [overview in the documentation](https://neo4j-contrib.github.io/neo4j-apoc-procedures/index33.html#_overview_of_apoc_procedures_functions) and detailed in subsequent sections.

Where can I find documentation for it.

Ahh, wait [Feature request : apoc support for MERGE for nodes and rels · Issue #271 · neo4j-contrib/neo4j-apoc-procedures · GitHub](https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/271) here it is mentioned that [Summer 2017 Release of the APOC Procedures Library](https://dzone.com/articles/summer-2017-release-of-the-apoc-procedures-library) contains references to

```auto
CALL apoc.merge.node(['Label'], {id:uniqueValue}, {prop:value,...}) YIELD node;
CALL apoc.merge.relationship(startNode, 'RELTYPE', {[id:uniqueValue]}, {prop:value}, endNode) YIELD rel;

```

I will play with it, since there is no documentation but I guess I can guess what it does. Maybe update the documentation would be a good service ;-)

Thanks for the pointer!!!

---

<div class="post-metadata">

**Author:** ![carib](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/carib/32/21301_2.png) [@carib](https://community.neo4j.com/u/carib)\
**Post date:** [March 9, 2021, 8:45pm UTC](https://community.neo4j.com/t/adding-multiple-labels-when-loading-from-csv/2351/7 "2021-03-09T20:45:09Z")

</div>

I was having this same exact problem, but apoc.merge.node did not solve my issue. I read the docs on this apoc statement, and it was not clear to me how to add multiple labels to only those nodes that are created with the MERGE + ON CREATE SET piece.

My question is: using MERGE ON CREATE SET, how can I add more labels only to those nodes that are created during the MERGE execution?

This is what gave me the result I was looking for:

```auto
LOAD CSV WITH HEADERS
FROM "file:///file.csv" AS row
MERGE(p:Person {id: row.id})
ON CREATE
              SET p:New,
                      p.name = row.name,
                      p.role = row.role,
                      p.location = row.location

```

I do this because this statement helps me add new nodes to my database. With the "New" label on these nodes, I can easily query these nodes to just focus on these to create the new relationships to the other nodes on the graph.

Is there a better way to do this with apoc.merge.node?

Thanks.
