Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-01-2020 06:31 PM
Currently, I perform these updates with multiple calls that return success or failure and use that result to determine whether to continue. In order to try and reduce the number of queries I'm trying to see if it's possible to do this update with a single call.
Here's the background. I have an API Endpoint that receives calls from Patreon for new and updated pledges. However, the email that the datapacket from Patreon sends may or may not match the email I have in the database. There's 4 different possibilities that I handle.
The actions for each are:
A user can then "claim" it by entering that email into a form where I query and create the Relationship. When the relationship is created, I delete the Pledge node.
Like I said, individually, these are very simple. I'm using the .Net Driver and simply create a session then call Run for the first query...if no results, run second...etc until final is to create the Pledge node.
My question is...can this be done with a single query? I've been trying to get it using CASE statements, but whenever I try to perform any operations I get an unexpected character error.
WITH 'lclay@kaolinsoftware.com' as patreonEmail
OPTIONAL MATCH (p:Person)-[r:IS_A_SUPPORTER {email: patreonEmail}]->(:Donation)
OPTIONAL MATCH (o:Person {email: patreonEmail})
OPTIONAL MATCH (m:Pledge {email: patreonEmail})
RETURN p, r, o, m,
CASE
WHEN p IS NOT NULL THEN
SET r.pledge_amount_cents = 100000
WHEN o IS NOT NULL THEN
'o not null'
WHEN m IS NOT NULL THEN
'm not null'
END AS results
01-03-2020 07:04 AM
The first thing I see is that SET is not supported in the CASE statement. The CASE statement is meant to evaluate a series of boolean expressions and return the first one that evaluates to true, and then returns the specified value or expression that evaluates to a value.
01-03-2020 02:27 PM
That's the idea I was getting, but wanted to make sure I wasn't misunderstanding it. I think I'm going to have to leave it as it is. It's not a big deal, but I just don't like seeing multiple if statements in a row 🙂
01-06-2020 01:16 AM
Okay, so you do have working code but have not posted it here.
Just a helpful comment. I find that when I post a question here, I get responses faster if I can provide code to build a tiny dataset to use for showing my problem, along with my code (working or not). It becomes a fun puzzle for someone else to solve for you.
01-06-2020 03:13 AM
@leelandclay http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/cypher-execution/conditionals/
please have a look at this..i think this can help you
01-09-2020 10:38 AM
@ganesanmithun323 That looks like exactly what I'm looking for. I've already moved onto another story at the moment so it'll be a while before I can test this, but I will
Thanks!!!!!
All the sessions of the conference are now available online