Is it possible to get an example to upsert an edge in orientdb. IF it does not exist is there a way to check if the edge exist, if it does then just update the edge else cre
via SQL you can use the basic UPDATE command
update written_by SET out = #9:2, in = #16:43, prop="gianni" UPSERT WHERE out = #9:2 and in = #16:43
http://orientdb.com/docs/last/SQL-Update.html
When you use "update written_by SET out = #9:2, in = #16:43, prop="gianni" UPSERT WHERE out = #9:2 and in = #16:43", it doesn't work properly for edges: it will create edge if it doesn't exist, but it will not create in and out properties in vertex, so, for example, you will not able to query MATCH. It works this way cos “The UPDATE/UPSERT works at document level, so it doesn't create the connections from the vertices. Using it, you will have a broken graph”, as authors said.
But you can use “upsert” for edges since version 3.0.1 and it will work properly – but you need to do the following:
Create unique index on edge_class (out, in) and – it's strange – The order is important! To do this, you need to create in and out properties first, otherwise db can't create index and there will be an exception when you will try to run command “Create index”. Then, use command CREATE EDGE UPSERT FROM TO .
In this case edge will be created only if it is not exists, and it will create in and out properties for vertex classes.