Logical Expressions

I am using neo4j 3.5.12 Community version

  • neo4j version community version.

We need to store logical expression in a property & execute it in run time.
if ( a> 5 & b >6)
{
return 'open'
}
What would be the best way to do in neo4j.

Thanks,
A.Anitha

Hi @anuvisha,

Welcome to the community. you can try below
return case when ( 5> 5 and 7 >6) then 'Open' else 'Close' end

You may want to review Max De Marzi's blog entry on decision trees, that sounds similar to what you're working with.

Does the returned value need to be part of what's stored, or can that be independent of it? You may be able to use apoc.cypher.run() from APOC Procedures to help, though either the entire expression would need to be valid CYPHER (a RETURN CASE WHEN ... type of query), or if you are only storing the a> 5 & b >6, then you'll need to supply the Cypher that will use that in a similar query.

Be aware that this type of dynamic query string generation does risk Cypher injection, so make sure you've vetted and cleaned the properties such that it can't escape intended usage and execute arbitrary Cypher.

Thanks Andrew.

The return value can be independent of whats stored. It can come through a API the whole expression is dynamic set through an User Interface.