Search code examples
orientdb

Deleting edge relationships via SQL


I'll try my best to explain the problem... after executing:

delete edge SOME_EDGE from (select from SourceNode where foo=bar) to (select from TargetNode where foo=bar)

When the last reference of an edge is deleted, the type name still persists in SomeClass with an empty list, ie:

"out_SOME_EDGE": []

Similar with in_SOME_EDGE and the inverse relationship.

Then when executing a query:

select from SourceNode where out_SOME_EDGE is not null

those classes with empty list references are still returned.

Obviously

select from SourceNode where out_SOME_EDGE=[]

doesn't do anything. How can I locate and/or remove these obsolete/empty edge references?

update SourceNode remove out_SOME_EDGE where out_SOME_EDGE is not null
update TargetNode remove in_SOME_EDGE where in_SOME_EDGE is not null

works, of course, but isn't the best way to go since TargetNode could still have valid references.

The deeper I get into trying to find a solution the more it seems like it's a bug that vertices are allowed to have edges with empty reference lists, or that those edges aren't removed when the last target reference is removed.


Solution

  • The empty list means that there are no relationship (In/Out)

    I think that that the delete edge command doesn't remove the field if the last reference is removed.

    Try this to locate empty relationship

    select from SourceNode where out_SOME_EDGE is not null or out_SOME_EDGE.size() = 0