Valeriy
Valeriy

Reputation: 1435

How to create graph with nodes and relationships using single Neo4j query?

I want to create a graph

  ___A____ 
 /   |    \
AA  AB    AC

My query is

create 
  a = (:Task {title:"A"}),
  aa = (:Task {title:"AA"}),
  ab = (:Task {title:"AB"}),
  ac = (:Task {title:"AC"}),
  (a)-[:DEPENDS_ON]->(aa),
  (a)-[:DEPENDS_ON]->(ab),
  (a)-[:DEPENDS_ON]->(ac)
return *;

But response

Neo.ClientError.Statement.SyntaxError Type mismatch: a defined with conflicting type Path (expected Node) (line 6, column 4 (offset: 125)) " (a)-[:DEPENDS_ON]->(aa)," ^

As far as I understand, only nodes or relationships can be created separately.

How to fix this query? Is it possible? If not, what is the easiest alternative to describe the graph in a query?

Upvotes: 0

Views: 47

Answers (1)

Valeriy
Valeriy

Reputation: 1435

Solved with. Thanks for @jose_bacoy

create 
  (a:Task {title:"A"}),
  (aa:Task {title:"AA"}),
  (ab:Task {title:"AB"}),
  (ac:Task {title:"AC"}),
  (a)-[:DEPENDS_ON]->(aa),
  (a)-[:DEPENDS_ON]->(ab),
  (a)-[:DEPENDS_ON]->(ac)
return *;

Upvotes: 1

Related Questions