4
votes

Is there a way to create both a Vertex and Edge in the same query?

I am aware that we can use out_EdgeName/ in_EdgeName to update the edge of a vertex if it already exists in an UPDATE query, but how to do that so that a new edge is created and assigned to the vertex?

Example use case in an Update Upsert query - a Vertex is being created and we require a new Edge to be created for that vertex. Can we do it in the same query or we would need 2 queries at least for that (i.e 2 UPDATE - UPSERTS)?

Taking cue from orientdb sql update edge? :

Something like - UPDATE Persons SET phone=000000, out_Inside=( UPDATE Edge UPSERT where in=@some_rid/sub-query, out=$this) where person_id=8

1

1 Answers

0
votes

This question is actual if you are using new version of orientdb 2.1. But as far as i know this features was implemented in 2.2 version.

"As far as I can tell, update works (including in/out):"

UPDATE FRIEND SET in=#11:5 WHERE in.name="Samantha" and out.name="Mat"

Although, using a query inside the set clause for in/out will cause it to return array:

UPDATE Friend SET in=(SELECT FROM User WHERE name="Jason") WHERE in.name="Samantha" and out.name="Mat"

Upsert also works, although when creating a new vertex it doesn't set the in/out properties. You could set the in/out properties your self, like this:

UPDATE Friend SET comment="Wazzzaup", in=#11:5, out=#11:6 UPSERT WHERE in.name="Jason" AND out.name="Mat"

It will result in a longer query when using sub-query for in= and out=, but at least it works (sub-query has same problem as above).

I got this information from issue: https://github.com/orientechnologies/orientdb/issues/1114#issuecomment-156585776