Search code examples
orientdborientdb-2.1

Making a copy of record without edges


Is there a way to make a copy of an arbitrary OrientDB record without its edges? I modified an original command (from the docs) for copying records and added fetchplan to it, but it does not work (frankly speaking to me it looks like there's a problem parsing this particular command, but hopefully im wrong)

This one executes fine, but edges remain:

insert into Test from select from Test where @rid=#102:119 fetchplan in_*:-2 out_*:-2

This one gives an error:

insert into Test from (select from Test where @rid=#102:119 fetchplan in_*:-2 out_*:-2)
com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.(SELECT FROM Test WHERE @rid = #102:119 FETCHPLAN in_*:-2 out_*:-2)

also tried smth like

insert into Test content (select @this.toJSON('fetchPlan:in_*:-2 out_*:-2') from Test where @rid=#102:119)

but that doesn't work either. Any thoughts? I'm on Orient 2.1.x


Solution

  • As workaround you can use this javascript function with one parameter (id)

    var g=orient.getGraph();
    var b=g.command("sql","select @this.toJSON('fetchPlan:in_*:-2 out_*:-2') as json from "+ id);
    if(b.length>0){
        var query="insert into Test content " + b[0].getProperty("json") ;
        var myVertex=g.command("sql",query);
        g.commit();
        return myVertex;
    }
    

    Using the following command

    select expand(result) from (select yourFunction(#102:119) as result)