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.

Convert Cypher field from boolean to string

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.

2 REPLIES 2

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