Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing subqueries in orientDB

Tags:

orientdb

This is the query i'm using right now :

INSERT INTO details SET name = "INITIALIZE",actionMap ={"1":12:1,"2":12:2};

Here 12:1,12:2 are rid's from another table.I'm facing a lot of problem's hardcoding these rid values.In order to avoid this i'd like to add the query like this

INSERT INTO details SET name = "INITIALIZE",actionMap ={"1":(select @rid from action where start is not null),"2":(select @rid from action where stop is not null)};

I'm getting this exception:

com.orientechnologies.orient.core.exception.OValidationException: The field 'details.actionMap' has been declared as LINKMAP but the value is not a record or a record-id

So how can i change my query to help my case.

like image 781
Sunilkumar 3560 Avatar asked Apr 06 '18 06:04

Sunilkumar 3560


1 Answers

This indeed can be done in a more gracefull way using batches.

This is just to create the object you want

INSERT INTO details SET name = "INITIALIZE"

We will turn this into

let $inserted = INSERT INTO details SET name = "INITIALIZE"

And add the edges you would like to add:

CREATE EDGE actionMap FROM $inserted TO (SELECT FROM action WHERE start is not null )
CREATE EDGE actionMap FROM $inserted TO (SELECT FROM action WHERE stop is not null )

So the entire batch you would have to run is

let $inserted = INSERT INTO details SET name = "INITIALIZE"
CREATE EDGE actionMap FROM $inserted TO (SELECT FROM action WHERE start is not null )
CREATE EDGE actionMap FROM $inserted TO (SELECT FROM action WHERE stop is not null )

If you have any more questions about this feel free to ask.

like image 58
mitchken Avatar answered Nov 15 '22 11:11

mitchken