Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-17-2022 02:37 PM
I have some Cypher code (test code) that uses APOC to load an Excel file and then process each row. What I want to do is this:
call apoc.load.xls('Test File.xlsx', 'Company',
// the file has a header row
{header:true})
yield map as row
with row
MERGE (c:Company)
ON CREATE
SET
c.name = coalesce(ltrim(rtrim(toString(row.Company
))), "UKNOWN"),
c.created = datetime()
ON MATCH
SET c.lastUpdated = datetime()
RETURN c
The problem is I only get 1 node, but have 5 distinct rows of data. It seems to be only processing the first row in the Excel file. Any ideas?
Solved! Go to Solution.
05-18-2022 08:37 AM
Yes, exactly, you should only put in the MERGE
clause the property that carry the constraint or the properties if you have a composite constraint.
05-18-2022 12:42 AM
Hello @mbandor
It is normal because you didn't specify an id property in the MERGE
clause so your query always MERGE
on the same node. Do you have a unique id for each row?
Regards,
Cobra
05-18-2022 05:32 AM
No. Each row may or may not have the same information I'm looking for, hence the need to split out the ON MATCH vs. ON CREATE function. If I don't use those, the script will iterate through each row just fine so I'm a little confused about how to proceed.
05-18-2022 05:34 AM
Share you data please
05-18-2022 05:37 AM
Company
Lockheed
Raytheon
Microsoft
Red Hat
Symantec
05-18-2022 05:39 AM
MERGE (c:Company {name: coalesce(ltrim(rtrim(toString(row.`Company`))), "UKNOWN"))
ON CREATE
SET c.created = datetime()
ON MATCH
SET c.lastUpdated = datetime()
RETURN c
05-18-2022 05:40 AM
Ah, so the name property (id) still needs to be in the merge statement. That is where I messed up. Thanks for clarifying.
05-18-2022 08:34 AM
One follow up question. For another node, there are multiple properties but the name property has a constraint. Should I only use the name property as the id and then set the others using the ON MATCH and ON CREATE?
05-18-2022 08:37 AM
Yes, exactly, you should only put in the MERGE
clause the property that carry the constraint or the properties if you have a composite constraint.
All the sessions of the conference are now available online