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.

Syntax error after CALL inside NOT EXISTS

I'm still learning and cannot figure out why I'm getting a syntax error on this statement.

Here's the error:
Neo.ClientError.Statement.SyntaxError
Invalid input 'CALL': expected "shortestPath", "allShortestPaths" or "(" (line 3, column 2 (offset: 45))
" CALL {"
^

Here's the statement:
MATCH (p:Practitioner)
WHERE NOT EXISTS {
CALL {
MATCH (p)-[r:SITS_FOR]->(e:Exam)
WHERE e.examType STARTS WITH 'STEP'
WITH p, MAX(e.latestExamDate) AS maxExamDate
RETURN p.fid AS pracFid, maxExamDate}
MATCH (p2:Practitioner {fid:pracFid})
WHERE maxExamDate < date("2015-01-01")
}
RETURN p

1 ACCEPTED SOLUTION

The WHERE NOT EXISTS clause applies to a graph pattern, and the reason this isn't working is you're trying to pass a sub-query to it.

Have a look at the exists function here -- and to improve this though, we'd need to get you to explain in more detail what you're trying to do with the query

View solution in original post

4 REPLIES 4

The WHERE NOT EXISTS clause applies to a graph pattern, and the reason this isn't working is you're trying to pass a sub-query to it.

Have a look at the exists function here -- and to improve this though, we'd need to get you to explain in more detail what you're trying to do with the query

Hi, David. Thank you for the quick response. If I were to write this in SQL, it would be something like this. I'm trying to return nodes that either do not have a certain exam type or have one, but the latest exam date is > 1/1/2015. Hopefully this helps.

SELECT Practitioner
FROM foo
WHERE Practitioner NOT IN (
SELECT Practitioner
FROM foo
JOIN (
SELECT fid AS pracFID, MAX(latestExamDate) AS maxExamDate
FROM bar
WHERE examType LIKE 'STEP%'
GROUP BY fid) x ON x.pracFID = foo.fid
WHERE x.maxExamDate < CONVERT(DATE,'01/01/2015')
)

I think I might rewrite this a very different way, something like:

MATCH (p:Practitioner)-[r:SITS_FOR]->(e:Exam)
WHERE NOT (e.examType STARTS WITH 'STEP')
WITH p, max(e.latestExamDate) as maxExamDate
(...)

But I can't figure what the next part is because I still can't tell what you're trying to do.

Key here is that I matched only those practitioners without the 'step' exam type, but from your existing queries I'm not sure what you want to do with the result. Maybe you want the actual last exam they took? That would be ...

MATCH (p:Practitioner)-[r:SITS_FOR]->(e:Exam)
WHERE NOT (e.examType STARTS WITH 'STEP')
WITH p, max(e.latestExamDate) as maxExamDate
MATCH (p)-[r:SITS_FOR { latestExamDate: maxExamDate }]->(e:Exam)
RETURN e

Thank you again, David, for responding so quickly. I think I'll go back to the drawing board on this. I'll mark your first reply as the solution, since that helped me understand why I can't use a CALL with a NOT EXISTS. Thanks again for your help!