cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to Merge and use toLower for the conditions

DevDan
Node Link

I have text data that I would like to allow both upper and lower case letters. But want to ignore case when doing merge operations.

For example, how do I apply toLower to o.name before it is compared to $name?

MERGE (u)-[:ACCESS]-(o:Object {name: toLower($name)})

 

1 ACCEPTED SOLUTION

You can approach it two ways that I can think of.  I am assuming the Object node exists, as 'where' can not be used with "merge." 

MATCH (o:Object)
WHERE toLower(o.name) = toLower($name)
MERGE (u)-[:ACCESS]-(o)
return u, o

or, with regex pattern

MATCH (o:Object)
WHERE o.name =~ "(?i)" + $name
MERGE (u)-[:ACCESS]-(o)
return u, o

 

View solution in original post

2 REPLIES 2

You can approach it two ways that I can think of.  I am assuming the Object node exists, as 'where' can not be used with "merge." 

MATCH (o:Object)
WHERE toLower(o.name) = toLower($name)
MERGE (u)-[:ACCESS]-(o)
return u, o

or, with regex pattern

MATCH (o:Object)
WHERE o.name =~ "(?i)" + $name
MERGE (u)-[:ACCESS]-(o)
return u, o

 

DevDan
Node Link

Thanks, I ended up using an optional match followed by an apoc.do.when on the object to simulate a merge with 

WHERE toLower(o.name) = toLower($name)