Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-18-2021 03:45 PM
Hi guys!
I have one relationship type (exported products from one country to another) named "EXPORTED_PRODUCT". On top of that i've created second relationship type based on the product code, as stated here:
MATCH (c1:Country)-[r:EXPORTED_PRODUCT]->(c2:Country) WHERE r.ProductHSCode="300220" MERGE (c1)-[:EXPORTED_PRODUCT_300220]->(c2)
Eveything looks fine, expect that any other link property, such as "ProductValue" and "ProductQuantity" don't copy at all.
Any ideas how can i duplicate these properties to the new relationship type?
11-18-2021 10:27 PM
SET r2 = r1
Need to be tested not sure, you need to create the r2 variable for your new relation as you did with the first one
11-20-2021 01:03 PM
Hi @tard.gabriel can you please make an example with the Cypher query? I'm not quite sure how to replicate what you've described...
11-20-2021 11:56 PM
MATCH (c1:Country)-[r1:EXPORTED_PRODUCT]->(c2:Country)
WHERE r.ProductHSCode="300220"
MERGE (c1)-[r2:EXPORTED_PRODUCT_300220]->(c2)
ON CREATE
SET r2 = r1
Not tested
11-21-2021 04:07 PM
@tard.gabriel it's not working. I've even tried with "WHERE r1.ProductHSCode="300220"" but no success whatsoever. Any other ideas perhaps?
11-22-2021 12:59 AM
Try this, it should work
11-23-2021 04:00 PM
for some reason your query returns "(no changes, no records)", but this works:
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country)
WHERE r.ProductHSCode="300220"
MERGE (c1)-[t:EXPORTED_PRODUCT_02]->(c2)
SET t.ProductHSCode=r.ProductHSCode,
t.ProductValue=r.ProductValue,
t.ProductQuantity=r.ProductQuantity,
t.Year=r.Year
11-23-2021 10:14 PM
It's simply because your relation already exist, that's why it's ON CREATE SET.
It will copy r1 in r2 only if the relation is created, if you want to do it systematically, your query is right. If you want to do it only when it matches an existing relationship you can use ON MATCH SET, so to recap you have :
SET
ON CREATE SET
ON MATCH SET
You also use both ON CREATE and ON MATCH when you need to define a different behaviour for each of them.
11-25-2021 09:20 AM
I would like to note that creating a new relationship type for each product is not a good practice. The property ProductHSCode on the relation EXPORTED_PRODUCT is quite sufficient to distinguish that. You just duplicate information with creating those new relations.
To clarify this exactly, we would need to know the full use case for these relationships and how they are queried later.
Best,
Reiner
11-25-2021 11:57 PM
Indeed, @Reiner got a point you won't be able to generalise a query and optimise it with parameters.
All the sessions of the conference are now available online