Inserting data into a Graph

Hi Team,

I have created a graph and trying to insert data, but I am not able to do. Let me know what I am doing wrong.

Here, I am trying to create 2 graphs and insert some date and delete all data with command “CLEAR GRAPH STORE -HARD” and validate if its deleting all data specific to that graph or for all graphs.

GSQL > ls
---- Graph test1
Vertex Types:
  - VERTEX Person(PRIMARY_ID name STRING, age INT, gender STRING, state STRING) WITH STATS="OUTDEGREE_BY_EDGETYPE"
Edge Types:
  - UNDIRECTED EDGE Friendship(FROM Person, TO Person, connect_day DATETIME)

Graphs:
  - Graph test1(Person:v, Friendship:e)
Jobs:
Queries:




GSQL > INSERT into Person (PRIMARY_ID, age, gender, state) values ("pp",1, "m","mo")
Encountered " "insert" "INSERT "" at line 1, column 1.
Was expecting one of:
    "@" ...
    "abort" ...
    "alter" ...
    "begin" ...

Hi @pramod.dba31 ,

The INSERT INTO ... syntax should be used inside a query.

Can you try creating the query below and run the query?

CREATE OR REPLACE QUERY test_add_data_to_person() {
    INSERT INTO Person (PRIMARY_ID, age, gender, state) VALUES ("pp",1, "m","mo");
}

You can see here for more details:

I hope this helps!

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph

Thanks for update.

Also with "CLEAR GRAPH STORE -HARD” will it clear only the specific graph where we ran under or will it clear all the data from all graphs.

I tried loading data and clear data. But "CLEAR GRAPH STORE -HARD” is deleting data from all Graphs.

How to clear only specific graph data.

GSQL > use graph test1
Using graph 'test1'
GSQL > select count(*) from Person
[
  {
    "v_type": "Person",
    "count": 2
  }
]
GSQL > use graph test2
Using graph 'test2'
GSQL > select count(*) from Person
[
  {
    "v_type": "Person",
    "count": 2
  }
]
GSQL > CLEAR GRAPH STORE -HARD
Abort all active loading jobs
Try to abort all loading jobs on graph test1, it may take a while ...
Try to abort all loading jobs on graph test2, it may take a while ...
Resetting GPE...
Successfully reset GPE and GSE
Stopping GPE GSE
Successfully stopped GPE GSE in 0.006 seconds
Clearing graph store...
Successfully cleared graph store
Starting GPE GSE RESTPP
Successfully started GPE GSE RESTPP in 0.295 seconds
GSQL > select count(*) from Person
[
  {
    "v_type": "Person",
    "count": 0
  }
]
GSQL > use graph test1
Using graph 'test1'
GSQL > select count(*) from Person
[
  {
    "v_type": "Person",
    "count": 0
  }
]

Hi @pramod.dba31 ,

There is currently no command to delete all data from one graph.

However, our Solution Engineer @Wyatt_Joyner had a workaround for this, which was to have a query like below in the graph:

CREATE OR REPLACE DISTRIBUTED QUERY test_delete() { 
    all = {ANY};
    delete_edges =
        SELECT s FROM all:s -(:e)- :t
        ACCUM DELETE (e);
    delete_verts = SELECT s FROM all:s POST-ACCUM DELETE (s);
}

If you have a lot of data, the version above may have large memory overheads. @Wyatt_Joyner has also suggested this version below which introduce the limits on how many vertices will be deleted in one query. You’ll have to run this query below multiple times, but it should use less memory than the version above:

CREATE OR REPLACE DISTRIBUTED QUERY test_delete_edge_limit(INT delete_count, INT edge_limit=-1) SYNTAX V1 { 
  all = {ANY};
  all = SELECT s FROM all:s LIMIT delete_count;
  IF edge_limit == -1 THEN
    delete_edges =
      SELECT s FROM all:s -(:e)- :t
      ACCUM DELETE (e);
  ELSE
    delete_verts =
      SELECT s FROM all:s -(:e)- :t
      SAMPLE edge_limit EDGE WHEN s.outdegree() > edge_limit
      ACCUM DELETE (e);
    all =
      SELECT s FROM all:s WHERE s.outdegree() <= edge_limit;    
  END;
  delete_verts = SELECT s FROM all:s POST-ACCUM DELETE (s);
}

If you have multiple nodes in the cluster, you should use the DISTRIBUTED keyword. If you only have 1 node, you should remove the DISTRIBUTED keyword from the query.

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph

Thank you.
Will let you know if any.