deadmousse
deadmousse

Reputation: 416

Neo4j: Collections containing null values can not be stored in properties

I have a csv where I want to use multiple columns in a single property. But not all columns are filled at the same time.

LOAD CSV WITH HEADERS FROM "file:c:/Users/emp.csv" AS row
CREATE (:Employee {ID: row.EID, Name: row.ENAME, Language: [row.L1, row.L2 , 
row.L3]});

Here, some values in L1 or L2 or L3 columns are empty.

I'm getting an error:'Collections containing null values can not be stored in properties.'

How do I solve this?

Upvotes: 1

Views: 1488

Answers (2)

cybersam
cybersam

Reputation: 66999

This might work for you:

LOAD CSV WITH HEADERS FROM "file:c:/Users/emp.csv" AS row
UNWIND [row.L1, row.L2, row.L3] AS x
WITH row, COLLECT(x) AS langs
CREATE (:Employee {ID: row.EID, Name: row.ENAME, Language: langs});

The UNWIND clause places L1, L2, and L3 in separate data rows; and the COLLECT aggregation function collects them together again, but ignoring any NULL values.

Upvotes: 1

Tomaž Bratanič
Tomaž Bratanič

Reputation: 6514

you can try using distinct to it filter out null values

LOAD CSV WITH HEADERS FROM "file:c:/Users/emp.csv" AS row
WITH *, distinct(row.L1 + row.L2 + row.L3) as langs 
CREATE (:Employee {ID: row.EID, Name: row.ENAME, Language: langs});

Upvotes: 0

Related Questions