Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-07-2018 08:17 AM
Depending on the result reported from one MATCH I would like to have different WHERE clauses. Is that possible?
A simple case is that if the first MATCH returns a null then I want to have one MATCH with WHERE and if it is not null I want a different MACTH,
An alternative is of course to do it in two seperate cypher queris and check the result from the first
11-07-2018 08:50 AM
You can do it with APOC, there is the procedure apoc.case
(read only queries) & apoc.do.case
(read & write queries) that do exactly what you want : https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_case_procedures
11-07-2018 09:02 AM
You need to use OPTIONAL MATCH
instead of MATCH
if you want the results to include null values. After OPTIONAL MATCH
you can use either APOC or a CASE plus UNWIND or FOREACH statements.
11-07-2018 02:30 PM
In any case a more concrete example would be helpful to ensure we're offering appropriate advice.
11-08-2018 02:10 AM
Might not be 100% syntacticaly correct but my orignail cypher was something like this
MATCH (f:F) --> (n:S ) MATCH (f:F) --> (p:P) MATCH (p:P)-->(t:T) where (( t.date <= f.date) RETURN t.data
But if f.date is equal "" then I would like to modify it to this
MATCH (f:F) --> (n:S ) MATCH (f:F) --> (p:P) MATCH (p:P)-->(t:T) RETURN t.data
11-08-2018 03:12 AM
The only difference between your two queries is the WHERE
clause no ? Results are the same.
So you can achieved it just by adding a predicate in your WHERE
clause like that :
MATCH (f:F)-->(n:S ),
(f)-->(p:P),
(p)-->(t:T)
WHERE
(NOT f.date = "" AND (t.date <= f.date)) OR
(f.date = "")
RETURN t.data
11-08-2018 08:35 AM
I tried to shorten my original cypher. This is a longer version of the WHERE clause
(( t.date <= f.date) AND ( NOT t.date = '' AND NOT t.date is null))
11-08-2018 02:23 PM
Ok, but it's the same thing, a OR
in your WHERE
clause is sufficient :
WHERE
(NOT f.date = "" AND t.date <= f.date AND NOT t.date = '' AND NOT t.date is null) OR
(f.date = "")
All the sessions of the conference are now available online