Sunilkumar 3560
Sunilkumar 3560

Reputation: 81

Writing subqueries in 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.

Upvotes: 6

Views: 531

Answers (2)

mitchken
mitchken

Reputation: 800

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.

Upvotes: 2

Valentin
Valentin

Reputation: 43

Adapted from this question

let $a1 = SELECT FROM action WHERE start IS NOT null
let $a2 = SELECT FROM action WHERE stop IS NOT null
INSERT INTO details SET name = "INITIALIZE", actionMap = {"1": $a1[0], "2": $a2[0]}

This is original answer and is for LINKLIST

Your error states:

The field 'details.actionMap' has been declared as LINKMAP but the value is not a record or a record-id

You are trying to store a value into a field that is supposed to store references

According to orientDB docs

You store references like this:

INSERT INTO Profiles SET name = 'Luca', friends = [#10:3, #10:4]

or with SELECT sub-querie:

INSERT INTO Diver SET name = 'Luca', buddy = (SELECT FROM Diver 
          WHERE name = 'Marko')

That will make your code to be:

INSERT INTO details SET name = "INITIALIZE", actionMap =[(SELECT FROM action WHERE start IS NOT null),(SELECT FROM action WHERE stop IS NOT null)];

Extra tip:

If you crate your actions in the same time, then you can add details and those 2 action with one query:

INSERT INTO details SET name = "INITIALIZE", actionMap = [(INSERT INTO yourActionTable SET yourActionField = 'yourFirstAction'), (INSERT INTO yourActionTable SET yourActionField = 'YourSecondAction')]

Upvotes: 0

Related Questions