How to change ELABEL on AgensGraph? - agens-graph

I want to change elabel of edge.
agens=# create (:v1{id:1})-[:e1{id:3}]->(:v1{id:2});
GRAPH WRITE (INSERT VERTEX 2, INSERT EDGE 1)
agens=# match ()-[r1:e1{id:3}]->() set r1:v2 remove r1:v1;
ERROR: syntax error at or near ":"
LINE 1: match ()-[r1:e1{id:3}]->() set r1:v2 remove r1:v1;
^
But, there is an error on it.
How to change ELABEL on AgensGraph?

There is no way to change label on edge on AgensGraph.
But, You can try add new edge with same properties and remove old edge.
agens=# create (:v1{id:1})-[:e1{id:3}]->(:v1{id:2});
GRAPH WRITE (INSERT VERTEX 2, INSERT EDGE 1)
agens=# match p = ( (n1)-[r1]->(n2) ) return p;
p
---------------------------------------------------------------
[v1[3.1]{"id": 1},e1[4.1][3.1,3.2]{"id": 3},v1[3.2]{"id": 2}]
(1 row)
agens=# match (n1)-[r1:e1{id:3}]->(n2)
create (n1)-[r2:e2]->(n2)
set r2 = properties(r1)
delete r1;
GRAPH WRITE (INSERT VERTEX 0, INSERT EDGE 1, DELETE VERTEX 0, DELETE EDGE 1, UPDATE PROPERTY 1)
agens=# match p = ( (n1)-[r1]->(n2) ) return p;
p
---------------------------------------------------------------
[v1[3.1]{"id": 1},e2[5.1][3.1,3.2]{"id": 3},v1[3.2]{"id": 2}]
(1 row)

Related

How to get max location id of label more faster on AgensGraph?

I want to get largest location id of label.
But, It is very slow on follow query.
agens=# match (n:v) return max(graphid_locid(id(n)));
max
-----
6
(1 row)
How to get max location id of label more faster on AgensGraph?
Fetch related sequence value from pg_sequences table.
agens=# select start_value from pg_sequences where schemaname = 'graph' and sequencename = 'v_id_seq';
start_value
-------------
6
(1 row)

Is there alternative of "similar to" on AgensGraph?

I want to find string using regular expression on AgensGraph.
agens=# create (:v1{value:'text'});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# match (n:v1) where n.value similar to 't%' return n;
ERROR: syntax error at or near "similar"
LINE 1: match (n:v1) where n.value similar to 't%' return n;
^
But, there is an error on it.
Is there alternative of "similar to" on AgensGraph?
Use operator "=~" for search using regex patten.
agens=# match (n:v1) where n.value =~ 't*' return n;
n
--------------------------
v1[3.1]{"value": "text"}
(1 row)

How to set offset with limit clause on AgensGraph?

I want to set offset with limit clause on AgensGraph.
But, there is no "offset" token.
agens=# create (:v1{id:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# create (:v1{id:2});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# create (:v1{id:3});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# match (n:v1) return n offset 1 limit 1;
ERROR: syntax error at or near "offset"
LINE 1: match (n:v1) return n offset 1 limit 1;
^
How to set offset with limit clause on AgensGraph?
Use "SKIP" instead of "OFFSET".
agens=# match (n:v1) return n skip 1 limit 1;
n
------------------
v1[3.2]{"id": 2}
(1 row)

How to modify property of label on AgensGraph?

I created new vertex on AgensGraph using CREATE statement.
How can I modify the properties of created vertex?
agens=# create (:v{prop:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# match (n:v{prop:1}) return n;
n
-------------------
v[3.1]{"prop": 1}
(1 row)
I want to following result after modifying vertex.
agens=# match (n:v{prop:2}) return n;
n
-------------------
v[3.1]{"prop": 2}
(1 row)
MATCH (a {prop:1})
SET a.prop=2;
--will do

How to create index on AgensGraph?

When traverse vertex or egde, It is very slow.
I want to create index for accelerating speed.
# match (n:v{id:1}) return n;
n
-----------------
v[3.1]{"id": 1}
(1 row)
Time: 693.100 ms
How can I create index for vertex or edge?
Use "CREATE PROPERTY INDEX" statement for create index on graph object.
# match (n:v{id:1}) return n;
n
-----------------
v[3.1]{"id": 1}
(1 row)
Time: 693.100 ms
# create property index on v ( id );
CREATE PROPERTY INDEX
Time: 2227.147 ms
# match (n:v{id:1}) return n;
n
-----------------
v[3.1]{"id": 1}
(1 row)
Time: 5.935 ms
In this case, accelerated over than hundred times.
Creating Index
agens=> CREATE PROPERTY INDEX ON [VERTEX OR EDGE LABEL] ([PROPERTY])
agens=> CREATE PROPERTY INDEX ON CUSTOMER (AGE)
Creating Unique Index (Allow only one edge between two vertices)
agens=> CREATE UNIQUE INDEX [INDEX NAME] ON [GRAPH_PATH.VERTEX OR EDGE LABEL] ([PROPERTIES])
agens=> CREATE UNIQUE INDEX STUDENT_UNIQ_INDEX ON [AGENS_GRAPH.CUSTOMER] ("start", "end")
Creating Unique Constraint
agens=> CREATE CONSTRAINT ON [VERTEX OR EDGE LABEL] [PROPERTY] IS UNIQUE
agens=> CREATE CONSTRAINT ON CUSTOMER CUSTOMER_ID IS UNIQUE

Categories

Resources