Convert Cypher field from boolean to string


(Fsportelli0) #1

Hello.
I need to convert a field in my Cypher query, from boolean to string.
Now, I execute this query:

MATCH (pref:XmlTag)
WHERE pref._name="orm_PreferredIdentifierFor"
RETURN DISTINCT COUNT(pref.ref) >0 AS isPreferred

Pref.ref has a value like a bunch of letters, or it's null. I'm just interested in priting "true" where pref.ref is set with a value no matter what, or "false" when is null.
I already solved this with the above query, but
with this workaround I obtain a java boolean type, but I need string. So, "true" or "false" in my result must be strings instead of boolean type.
Is there a way to do this?

Thanks in advance.


(Oleg ) #2

Could you use a CASE statement?
https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#query-syntax-case


(Andrew Bowman) #3

oleg_neo4j is correct, CASE would work here, but for this case it will be faster to just use toString():

MATCH (pref:XmlTag) 
WHERE pref._name="orm_PreferredIdentifierFor" 
WITH DISTINCT COUNT(pref.ref) > 0 AS isPreferred
RETURN toString(isPreferred) as isPreferred