Concatenation of String in neo4j

Asked by At

I have to create a node in neo4j where I have to add a long neo4j query as a property in the create node query.

create (n:HMP_QUERY_NODE{attributeTypes: '"attrMap":{}',dependentId:111,isSingle:false,
 nodeCategory:'CXCustomerHierarchy,CAVHierarchy',
queryDesc:"",
queryId:123,queryLabel:"Comparison report CSAV_CX_CUST Report",queryName:"CSAV_CX_CUST Report", 
queryOptionId:25 ,queryOptions:"" ,status:"A"}) RETURN n

In queryDesc property I have to add

MATCH(cav:CustomerAccountViewHierarchy)-[:_properties]->(auditnode)-->(spoke) 
WHERE spoke._type='CAVCustomer'  AND spoke.start_date <= timestamp() <= spoke.end_date AND spoke.status = "Confirmed"
WITH spoke as cavspoke
OPTIONAL MATCH(cxc:CXCustomerHierarchy)-[:_properties]->(auditnode)-->(spoke)
WHERE spoke._type='CXCustomer' AND spoke.start_date <= timestamp() <= spoke.end_date AND spoke.status = "Confirmed"
AND spoke.sourceSystemId = cavspoke.sourceSystemId
WITH cavspoke,cxc,spoke as cxcspoke
WHERE (cxc is null) OR (cxcspoke.CXCustomer <> cavspoke.elementLabel)
WITH cavspoke,cxcspoke
return distinct cavspoke.elementLabel,cavspoke.sourceSystemId,cxcspoke.CXCustomer,cxcspoke.sourceSystemId

as a property

Its giving me syntax error

2 Answers

2
logisima On Best Solutions

Your query property meed to be a string, and for that you need to escape all the " by \" or by removing if it's possible.

For example, here I have replaced all the " by ' :

MATCH(cav:CustomerAccountViewHierarchy)-[:_properties]->(auditnode)-->(spoke) 
WHERE spoke._type='CAVCustomer'  AND spoke.start_date <= timestamp() <= spoke.end_date AND spoke.status = 'Confirmed'
WITH spoke as cavspoke
OPTIONAL MATCH(cxc:CXCustomerHierarchy)-[:_properties]->(auditnode)-->(spoke)
WHERE spoke._type='CXCustomer' AND spoke.start_date <= timestamp() <= spoke.end_date AND spoke.status = 'Confirmed'
AND spoke.sourceSystemId = cavspoke.sourceSystemId
WITH cavspoke,cxc,spoke as cxcspoke
WHERE (cxc is null) OR (cxcspoke.CXCustomer <> cavspoke.elementLabel)
WITH cavspoke,cxcspoke
return distinct cavspoke.elementLabel,cavspoke.sourceSystemId,cxcspoke.CXCustomer,cxcspoke.sourceSystem

So now I can use it in your query :

create (n:HMP_QUERY_NODE{attributeTypes: '"attrMap":{}',dependentId:111,isSingle:false,
 nodeCategory:'CXCustomerHierarchy,CAVHierarchy',
queryDesc:"MATCH(cav:CustomerAccountViewHierarchy)-[:_properties]->(auditnode)-->(spoke) 
    WHERE spoke._type='CAVCustomer'  AND spoke.start_date <= timestamp() <= spoke.end_date AND spoke.status = 'Confirmed'
    WITH spoke as cavspoke
    OPTIONAL MATCH(cxc:CXCustomerHierarchy)-[:_properties]->(auditnode)-->(spoke)
    WHERE spoke._type='CXCustomer' AND spoke.start_date <= timestamp() <= spoke.end_date AND spoke.status = 'Confirmed'
    AND spoke.sourceSystemId = cavspoke.sourceSystemId
    WITH cavspoke,cxc,spoke as cxcspoke
    WHERE (cxc is null) OR (cxcspoke.CXCustomer <> cavspoke.elementLabel)
    WITH cavspoke,cxcspoke
    return distinct cavspoke.elementLabel,cavspoke.sourceSystemId,cxcspoke.CXCustomer,cxcspoke.sourceSystem",
queryId:123,queryLabel:"Comparison report CSAV_CX_CUST Report",queryName:"CSAV_CX_CUST Report", 
queryOptionId:25 ,queryOptions:"" ,status:"A"}) RETURN n
1
Raj On

You might be getting error because there are double quotes in the query Description.

You need to escape these double quotes. Surround this description with double quotes and Escape the double quotes from the description by replacing it with 2 double quotes.

Refer Neo4j doc here for more details: https://neo4j.com/developer/kb/how-do-i-use-load-csv-with-data-including-quotes/