2

It may seem duplicate of this but it is not. Can we make cypher query case insensitive based on fields. I know we can use regex for values but we need it based on fields.

e.g.

MATCH (c:customer) WHERE c.CUSTOMERNUMBER = '1088' RETURN c

Above query returns a result, but following does not

MATCH (c:Customer) WHERE c.CustomerNumber = '1088' RETURN c

Here lable Customer and property CustomerNumber are having different cases.

Vikas
  • 6,868
  • 4
  • 27
  • 41

1 Answers1

2

You can use PROPERTIES to get a map representation of a node, and then use KEYS so that you can iterate over them. Because "Name", "NAME", and "Prop1" are all equally unique property names, and they can all or none exist, as far as the DB is concerned. You will have to iterate every property of the node to find a field that matches your criteria.

MATCH (n) 
WHERE ANY(key in KEYS(n) WHERE lower(key)="name" AND n[key]="Neo") 
RETURN n

This is more flexible than simple case insensitivity, but it is also expensive.

Tezra
  • 8,463
  • 3
  • 31
  • 68
  • You can replace `KEYS(PROPERTIES(n))` with `KEYS(n)`. – cybersam May 17 '19 at 20:58
  • Thanks for your answer. But is there any configuration setting that we could use for this. Like in RDBMS we have COLLATION – Vikas May 18 '19 at 03:47
  • @Code_Mode right now, Neo4j doesn't have any settings like that. Though one other thing you could do is standardize the field names before writing them in Neo4j. – Tezra May 20 '19 at 12:09
  • Yes we did that only. Standardised the field and Label names – Vikas May 20 '19 at 16:07