Graqn insert query scope


#1

I am trying to figure out how GRAQL keeps the scope for variables. For instance this works:

insert $entity1 isa company has name “Something”;
$entity2 isa project has name “Project”;
(childProject: $entity2, parentCompany: $entity1 ) isa companyProject;

This doesn’t:

insert $entity1 isa company has name “Something”;
insert $entity2 isa project has name “Project”;
insert (childProject: $entity2, parentCompany: $entity1 ) isa companyProject;

So it looks like var scope is only limited to the single statement. My issue is that i have relationships that need to access the object that is previously inserted. If i do this with a single insert, GRAKN hangs and takes 100 % of the CPU, so this is not an option for me.

Thank you very much,
Angel


#2

Hei @attodorov,

you are right, the scope for variables is limited to single statement.

If you need to split big statements, you can refer to relationships that were previously inserted using the match...insert paradigm, you can read the doc about it here.

So that you can first insert what you need:

insert
$entity1 isa company has name “Something”;
$entity2 isa project has name “Project”;

and later in time you can refer to these same things in another match...insert statement

match 
$entity1 isa company has name “Something”; 
$entity2 isa company has name "Project";
insert
(childProject: $entity2, parentCompany: $entity1 ) isa companyProject;

Hope that helps,

Marco


#3

Thanks a lot Marco

that worked! I have previously tried a similar thing, without success, by putting the match keyword on each line ( like a separate statement), but your example works perfectly fine.