LOAD CSV how to ignore case in the column headers

Neo4j 4.3 Community edition running on Ubuntu 20.04

Just a short question: is there a way to ignore the case on the column name while importing with LOAD CSV?

As I received the file directly from different users, sometimes they write down the correct column name, but with the wrong case.

I cannot modify the data before the import, so the question.

Any idea?

@paolodipietro58

Maybe as a fast solution,
you can transform the map keys to lower case (or upper case) coming from the LOAD CSV using the apoc.map.fromLists procedure, if you can use it.


That is:

LOAD CSV WITH HEADERS FROM 'file:///my_file.csv' AS line
// transform map keys to lowerCase
WITH apoc.map.fromLists([k IN keys(line) | toLower(k)], [k IN keys(line) | line[k]]) as line
return line.column1, line.column2  // do stuff with lower column header keys
1 Like

You can try using position indexes instead of the header names. For example:

load csv from 'file:///myFile.csv' as row
with row
skip 1
then reference each subsequent column as row[0], row[1], row[2], etc.

I experimented and you can't use column indexes using 'with headers', so you need to skip the first 1 row to skip the header row.

Not always the columns are ordered, so this solution is not applyable!