Clark Richey
Clark Richey

Reputation: 392

order by when some properties contain arrays

I have a database where the same type of node, lets say person, may have either a single string value for a given property or an array of string values. I want to be able to conduct a search and then order results by this property. When attempting that I receive the following error:

KernelException: Don't know how to compare that. Left: ["D'Amico","Damico"] (String[]); Right: "Brindley" (String)

Any thoughts on how this can be accomplished?

Upvotes: 1

Views: 159

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

If it was ok to sort by the first array element you could try.

MATCH (n)
RETURN n
ORDER BY coalesce(head(n.foo), n.foo)

head(coll) returns null if there is no collection, then you just use the property normally.

Upvotes: 3

Related Questions