Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-08-2022 09:38 AM
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
07-08-2022 09:55 AM
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
07-08-2022 10:27 AM
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.
07-08-2022 10:44 AM
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
07-08-2022 10:54 AM - edited 07-08-2022 11:09 AM
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.
07-08-2022 11:46 AM
@TrevorS , you marked a solution but this is not resolved yet. The post you marked is a troubleshooting step. Please unmark.
07-08-2022 12:21 PM
My apologies @tk. I removed the solution from the post.
07-08-2022 12:22 PM
No problem! Thank you
07-08-2022 12:43 PM
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?
07-08-2022 01:33 PM
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.
07-08-2022 01:38 PM
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...
07-11-2022 07:10 AM
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.
07-11-2022 02:59 PM
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.
07-11-2022 05:38 PM
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.
All the sessions of the conference are now available online