Devika Awasthi
Devika Awasthi

Reputation: 7

Multiple statements in THEN clause of CASE statements in Cypher query

I am pretty new to Neo4j. Is it possible to have an operation performed in the THEN clause of a CASE statement in CYPHER query? Something like, if the output of my current processing is null, then do something else. Snippet of what I am trying to do is below:

MATCH (order:PurchaseOrder)-[r:HAS_ITEM]->(a:sku) where a.id ='' and id(order) in OrderIDs

    with order as commonorders 
        CASE  WHEN  commonorders is not NULL THEN 

    [MATCH (commonorders)-[r:HAS_ITEM]->(a:sku) where a.id <> '888888888'
    return a]
ELSE
[ MATCH (order:PurchaseOrder)-[r:HAS_ITEM]->(a:sku) where a.id in [] and id(order) in OrderIDs

    WITH a as recommendedSku , count(r) as skuCount
ORDER BY skuCount DESC
LIMIT 5]

END

Upvotes: 0

Views: 1607

Answers (1)

cybersam
cybersam

Reputation: 66967

The THEN and ELSE clauses cannot invoke MATCH (nor mutating operations, like CREATE). Also, a Cypher query cannot have multiple RETURN clauses (except when UNION is used, which would be inappropriate in your case).

You should split the query into two; or, if possible, modify your data model so that a single query would suffice.

Upvotes: 2

Related Questions