Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-01-2022 05:32 AM
I would like to create two types of nodes (CHEMICAL & DISEASE) and their relationships from Relation column. There could be 4 combinations (Source_CHEMICAL--Relation-->Target_CHEMICAL, Source_CHEMICAL--Relation-->Target_DISEASE,Source_DISEASE--Relation-->Target_CHEMICAL,Source_DISEASE--Relation-->Target_DISEASE)
id | SourceType_CHEMICAL | SourceType_DISEASE | Relation | TargetType_CHEMICAL | TargetType_DISEASE |
1 | cardiac myosin | induce | myocarditis | ||
2 | nitric | inhibit | chrysin | ||
3 | sesame peptide powder | exhibited | angiotensin | ||
4 | allergen | induce | hypersensitivity | ||
5 | leucoencephalopathy | caused | infection |
I tried using below query, but it didn't work and gave an error for below line,
"MERGE(c1)-[:row.Relation]->(c2)"
Neo.ClientError.Statement.SyntaxError: Invalid input '.': expected
can someone help with this? Thanks
#cypher #query
Solved! Go to Solution.
07-02-2022 05:00 AM
Unfortunately you cannot have dynamic relationship-types in plain cypher.
You'd either have to do a multi-pass over the with a WHERE filter on the rel-type column and different cypher-statements (or perhaps subqueries).
LOAD CSV ... AS row
CALL { with source, target, row
WITH * WHERE row.relationship = 'induce'
MERGE (source)-[:INDUCE]->(target)
}
...
Or you can use
call apoc.create.relationship(source, type, properties, target) yield rel
07-02-2022 05:00 AM
Unfortunately you cannot have dynamic relationship-types in plain cypher.
You'd either have to do a multi-pass over the with a WHERE filter on the rel-type column and different cypher-statements (or perhaps subqueries).
LOAD CSV ... AS row
CALL { with source, target, row
WITH * WHERE row.relationship = 'induce'
MERGE (source)-[:INDUCE]->(target)
}
...
Or you can use
call apoc.create.relationship(source, type, properties, target) yield rel
08-07-2022 02:16 AM
Thank you very much and I'm very sorry for being so late in thanking you for providing a solution
All the sessions of the conference are now available online