Creation of Edge in Query

Hi Team,

Is there a way to create new edge between two selected vertex sets or do we have to always create a schema change job(to create new edge), run job and use “insert into” to add data?

Cant we create an edge just like merge in neo4j? instead of always running a schema change job for adding new edges.

eg: Wanted to create an edge between cust and own in the query itself, without creating and running schema change job for adding new edge

Yes, you can insert edges within the logic of your GSQL query, you do not need a loading job.

Here are two simple examples:

Vertex tx;
Vertex st;

T = {TaxId.*};
S = {Store.*};
T1  = select t from T:t
        WHERE t.taxIdNumber == taxId
        POST-ACCUM tx = t;

S1 = select s from S:s
        WHERE s.storeName == storeName
        POST-ACCUM st = s;

INSERT INTO HAS_TAX_ID VALUES (st, tx, now());

===========

Vertex tx;

S = {Store.*};

T1 = select t from T:t
WHERE t.taxIdNumber == taxId
POST-ACCUM tx = t;

S1 = select s from S:s
WHERE s.storeOwner == owner
POST-ACCUM INSERT INTO HAS_TAX_ID
VALUES (s, tx, now());

1 Like

Hi Markmegerian,

It says “HAS_TAX_ID” is not a vertex type, an edge type or a string variable. Even if I dont have an edge “HAS_TAX_ID” in graph will it create one? with out schema change job?

@karnamthulasiram TigerGraph follows a schema first approach. To populate a new edge, the edge needs to first be created if it doesn’t exist. One way you could bypass this (if you so choose) is by creating a generic edge with a property type as an attribute.

Person - (RELATIONSHIP) - Person

  • attr: r_type

Person - (RELATIONSHIP) - Person

  • r_type: FATHER

Person - (RELATIONSHIP) - Person

  • r_type: MOTHER

and so on


My recommendation would be to run a schema change job if you are looking to add new edge types.

I was just giving an example - i was under the impression that you wanted to insert an edge that was already defined in your schema, during the execution of a GSQL query. i apologize if i misunderstood the question. sounds like you want to do a CREATE EDGE.

1 Like

Thanks you @markmegerian and @Jon_Herke