cancel
Showing results for 
Search instead for 
Did you mean: 

STRING Equality Not Returning Expected Results

tk
Node Link

Hello, I have a simple cypher query with a WHERE clause and not other logic that looks something like: 

WHERE node.propValue = 'string value with spaces'

Replacing the "=" with CONTAINS, STARTS WITH, ENDS WITH, and TRIM() returns the expected results without changing the value right of the equals sign.

To troubleshoot, I have checked that the type of the property value I am expecting is STRING. I have used the SIZE() function to check for leading or trailing characters. 

Any ideas? 

Thank you

13 REPLIES 13

glilienfield
Ninja
Ninja

Running the two cypher statements sequentially, a match was returned.  What does the property look like when you return it? 

create(m:String) set m.propValue = 'string value with spaces';

match(m:String) where m.propValue = 'string value with spaces'
return m

 

When I return the value, there is no difference between the output and what I have in the where clause when I used the "=". I even exported the result produced when using the CONTAINS to CSV, opened in Notepad++ to ensure no special characters, etc. , re-pasted the value in the query and re-ran with the "=" but nothing returned. Really confused by this.

me too.  So, you get a result returned with all three: 'contains', 'starts with', and 'ends with'?  The only way that is possible is if the string is equal to the literal value or the string is a concatenation of the literal value, any literal string, and the literal value. That of course, is not the case for you, so the string should be equal to the literal value.  

Try the following to see what each character is:

match(node)
WHERE node.propValue CONTAINS 'string value with spaces'
with node.propValue as x
with x, size(x) as size
with x, range(0,size-1) as indexes
unwind indexes as index
return substring(x, index, 1) as character

You are correct; I get the expected results when using 'contains', 'starts with', and 'ends with' but also when using toString and trim functions on node.propValue

After running the above in my environment I get the expected results of: 

"s"
"t"
"r"
"i"
"n"
"g"
""
"v"
"a"
"l"
...
...
...
"e"
"s"

That seems to check out. Thank you for all your help with this.

tk
Node Link

@TrevorS , you marked a solution but this is not resolved yet. The post you marked is a troubleshooting step. Please unmark.

TrevorS
Community Team
Community Team

My apologies @tk. I removed the solution from the post. 

TrevorS
Community Specialist

No problem! Thank you

glilienfield
Ninja
Ninja

What happened to the latest posts?  Anyway, when you outputted the characters, what did the ellipses represent?  Did you get every character, and only those, from the literal string?  

No idea what happened to those other posts. Hopefully a moderator can get them back because they were useful for context. 


Correct. Every character, including spaces, from the literal string were returned and nothing more. Not sure if you saw, but using toString(node.propValue) also returns expected results. 

TrevorS
Community Team
Community Team

I dont see any posts missing from the thread here. The last I can see is the link below.
https://community.neo4j.com/t5/neo4j-graph-platform/string-equality-not-returning-expected-results/m...

TrevorS
Community Specialist

tk
Node Link

Happy Monday all. Wanted to float this to the top to see if anyone has an idea of why my string equality WHERE clause does not return expected results, however, CONTAINS, STARTS WITH, ENDS WITH, TRIM(), and toSTRING() does. 

tk
Node Link

Any other troubleshooting steps would also be appreciated. I could very well be overlooking something basic so any input is valuable to me. Thanks again.

I don't have any further suggestions. If the property's value is the same character-by-character, then the property and the literal string should be equal. Maybe raise it as a defect with Neo4j.