0
votes

Neo.ClientError.Statement.SyntaxError: Invalid input ')': expected whitespace or a relationship pattern (line 66, column 100 (offset: 1898)) "CREATE (z:Subscription{ subscriptionId: subs.subscriptionId, startDate: subs.startDate, endDate:''})<-[r:ASSOCIATION]-(y:Person {nationalIdentityNumber: subs.nationalIdentityNumber, name: subs.name, surname: subs.surname, fathername: subs.fathername , nationality: subs.nationality, passportNo: subs.passportNo, birthdate: subs.birthdate})"

I want to create/merge nodes and relation that types are Person, Subscription and Line

If I had same subscription I should check to startDate, If new data's start date greater then old data; I sould create new Subscription and also change old subscription's end date.

UNWIND  [{
msisdn:'99658321564',
name:'Lady',
surname:'Camble',
fatherName:'Aeron',
nationality:'EN',
passportNo:'PN-1234224',
birthDate:'12-05-1979',
nationalIdentityNumber:'112124224',
subscriptionId:'2009201999658321564',
startDate:'20-09-2019 12:00:12'
},{msisdn:'99658363275',
name:'John',
surname:'Mckeen',
fatherName:'Frank',
nationality:'EN',
passportNo:'PN-126587',
birthDate:'15-08-1998',
nationalIdentityNumber:'2548746542',
subscriptionId:'1506201999658363275',
startDate:'15-06-2019 13:00:12'}
{
msisdn:'99658321564',
name:'Lady',
surname:'Camble',
fatherName:'Aeron',
nationality:'EN',
passportNo:'PN-1234224',
birthDate:'12-05-1979',
nationalIdentityNumber:'112124224',
subscriptionId:'2009201999658321564',
startDate:'31-11-2019 12:00:12'
}
] as subs
MERGE (y:Person {nationalIdentityNumber: subs.nationalIdentityNumber, name:         subs.name, surname: subs.surname, fathername: subs.fathername , nationality: subs.nationality, passportNo: subs.passportNo, birthdate: subs.birthdate  })
MERGE (t:Subscription{subscriptionId:subs.subscriptionId })
MERGE (y)-[rel:ASSOCIATION]-(t)
ON MATCH SET
t.endDate = (case when t.startDate <subs.startDate then subs.startDate else '' 
end) 
MATCH (t:Subscription) where t.subscriprionId=subs.subscriprionId and
(CASE
WHEN  t.endDate=subs.startDate then 
CREATE (z:Subscription{ subscriptionId: subs.subscriptionId, startDate: subs.startDate, endDate:''})-[r:ASSOCIATION]-(y:Person {nationalIdentityNumber: subs.nationalIdentityNumber, name: subs.name, surname: subs.surname, fathername: subs.fathername , nationality: subs.nationality, passportNo: subs.passportNo, birthdate: subs.birthdate})
END)
 RETURN y
2

2 Answers

0
votes
UNWIND[...] as subs
MERGE (y:Person {nationalIdentityNumber: subs.nationalIdentityNumber, name: subs.name, surname: subs.surname, fatherName: subs.fatherName , nationality: subs.nationality, passportNo: subs.passportNo, birthDate: subs.birthDate  })
MERGE (t:Subscription{subscriptionId:subs.subscriptionId,startDate:subs.startDate,endDate:''})
MERGE (y)-[rel:ASSOCIATION]-(t)
MERGE(x:Subscription{subscriptionId:subs.subscriptionId, endDate:''})
SET
x.endDate = (case when x.startDate < subs.startDate then subs.startDate else null end);

CQL should like this. Thanks my co-worker.

0
votes

You're trying to have conditional Cypher clauses through a CASE statement, and that won't work. You can't do a nested CREATE (or any other Cypher clause) in a CASE.

You can however use a trick with FOREACH and CASE to mimic an if conditional. That should work in your case, as you want to only execute a CREATE under certain conditions (though since you already matched to the y node for the person, just reuse (y) in that CREATE instead of trying to define the entire node again from labels and properties, that won't work properly).

If you need more advanced conditional logic, that's available via conditional procs in APOC Procedures