Search code examples
javagraph-databasesvaticle-typeqlmindmapsdbvaticle-typedb

Graql insert query: duplicate Var objects


Var message = var().isa("message");
insert(message).execute();

Var relation = var().isa("connection")
    .rel("role1", id("existing-id"))
    .rel("role2", message);
insert(relation).execute();

Executing the following creates two instances of a message.

Is this expected? If it is, is it because I did not assign an ID, or because I have used two insert statements?


Solution

  • This is the expected behaviour. You're correct at guessing that assigning an id will solve the issue:

    Var message = var().id("my-message").isa("message");
    

    The reason this happens is because a Var does not represent a single concept. Instead, it represents a pattern to match in the graph. In this instance, the Var only says "things that are messages", not any particular message.

    You could also assign a variable name, e.g. Var message = var("x"). ... For this to work, you would have to execute only a single insert.