Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-08-2021 11:07 AM
WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url CALL apoc.load.jdbc(url,"customerinfo") YIELD row MERGE(customer:Customer{customerNumber:row.customerNumber, ContactName: row.ContactName});
WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url CALL apoc.load.jdbc(url,"productinfo") YIELD row MERGE (product:Product {productCode: row.productCode, productLine:row.productLine});
WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url CALL apoc.load.jdbc(url,"orderinfo") YIELD row MERGE (a:Order {orderNumber: toInteger(row.orderNumber)}) MERGE (b:Product {productCode: row.productCode}) MERGE (a)-[:PRODUCT]->(b);
so when i hover over the product relationship, i do not see the productLine which is a property belonging to the product node.
06-08-2021 12:19 PM
MERGE is more complex than you realize, and your queries are not doing what you think they're doing. You're creating additional nodes because even though there are :Product nodes with the productCode
you're looking for, they don't have productLine
properties, so a new node is created instead, leaving you with multiple :Product nodes that have the same productCode
but having different sets of properties. You should be using MERGE only on the properties that uniquely identify the nodes you want, then use SET or ON CREATE SET
or ON MERGE SET
after your MERGE to set the additional properties.
More information on using MERGE here:
06-08-2021 09:51 PM
thank you Andrew, that seems to be the issue. However, i am not able to fix it. I tried using Coalesce but it doesnt work. As I am new to neo4j, can i ask you to help me with the syntax please ?
WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url
CALL apoc.load.jdbc(url,"orderinfo") YIELD row
MERGE (a:Order {orderNumber: COALESCE(row.orderNumber, "UNAVAILABLE")})
MERGE (b:Product { productCode: COALESCE(row.productCode, "UNAVAILABLE")})
MERGE (a)-[:PRODUCT3]->(b);
Tried ON CREATE too, but it seems to create UNAVAIL for all
WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url
CALL apoc.load.jdbc(url,"orderinfo") YIELD row
MERGE (a:Order {orderNumber: row.orderNumber})
MERGE (b:Product {productCode:row.productCode})
ON CREATE SET b.productLine='UNAVAIL'
MERGE (a)-[r1:PRODUCT15]->(b)
RETURN a,r1,b limit 50;
06-10-2021 01:08 AM
That just indicates the productCode is always null. Have you maybe misspelled it?
All the sessions of the conference are now available online