Re: [Neo4j] ternary operator/default value in neo4j cypher

134 views
Skip to first unread message

Andres Taylor

unread,
Jul 24, 2012, 11:44:51 AM7/24/12
to ne...@googlegroups.com
Nothing like this exists. It's a really good suggestion though. 

As a side note - this is something I would love help with. There are a number of different ways to do this though, and it would be really helpful if someone could research the topic a bit an make a suggestion. I come from a T-SQL background, and there you use CASE. C# has the ternary operator. I'm very fond of Scala's match operator. What is a good fit for Cypher?

Andrés

On Tue, Jul 24, 2012 at 2:09 PM, Robin Kc <arora....@gmail.com> wrote:

I need to implement something of a ternary operator that can help me return some default values from cypher query itself.

Scenario is -

if an employee's city is Delhi, return 5 else return 10

Something like a ternary operator.

start employee = node(5)
return employee.city == 'DELHI' ? 5 : 10 as val;

I tried things like

start employee = node(5)
return coalesce (employee.city == 'DELHI', 5)

but no luck.

Is there a way to implement such a scenario in neo4j be it Cypher or Traversal.

I have posted the same question on stackoverflow - http://stackoverflow.com/questions/11629913/ternary-operator-default-value-in-neo4j-cypher




--
The best way to ask for Cypher help: http://console.neo4j.org/usage.html 

Jim Webber

unread,
Jul 27, 2012, 12:17:02 PM7/27/12
to ne...@googlegroups.com
Forgive my meddling in this one, but I confess to being a little wary of this notion.

I rather like that Cypher is very graph focussed, and addresses the domain of the database. If we choose to add in functionality like this, Cypher becomes more and more like a general-purpose programming language. I don't think that's helpful because:

1. We know it's not a good idea to encode business logic in queries..
2. There are lots of good programming languages out there already which can easily handle the return val = "DELHI" ? 5 : 10 case. Note that neither 5 nor 10 are actually about data access and manipulation here, they're domain things.

Even if those features existed in Cypher today, I don't think in good conscience I would use them to develop a business information system - I think it conflates concerns.

Just my £0.02.

Jim

Max De Marzi Jr.

unread,
Jul 27, 2012, 6:15:51 PM7/27/12
to ne...@googlegroups.com
People put all kinds of business logic in SQL queries. If cypher is to be the graph equivalent of SQL it needs to be able to handle business logic.

It needs to. Will it make cypher less pure? Absolutely, but we have to be pragmatic here.

Michael Hunger

unread,
Jul 28, 2012, 8:50:30 AM7/28/12
to ne...@googlegroups.com
Agree w/ Max

We should enable people to solve their problems easily and kick ass doing so


Sent from mobile device
Reply all
Reply to author
Forward
0 new messages