Is there alternative of "similar to" on AgensGraph? - agens-graph

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)

Related

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 change ELABEL on AgensGraph?

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)

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

What is the casting in AgensGraph ver 1.3 double quote

I used agensgraph version 1.3.
Following query
'MATCH (a:movie) RETURN a.title
gives result:
title
---------------------------------
"The Matrix"
"The Matrix Reloaded"
"The Matrix Revolutions"
"The Devils Advocate"
"A Few Good Men"
"Top Gun"
"Jerry Maguire"
"Stand By Me"
I don't know why is double quote operator.
What is the way to replace ""?
You can use function "btrim" for removing needless quotes.
agens=# select btrim( n.value::text, '"' ) from ( match (n) return n.value ) as n;
btrim
-------
test
(1 row)
You must use trim on SQL part of quires for removing quotes.

Does snowflake support positive lookbehind in a regex?

I want to use a positive lookbehind as part of my regexp_substr expression.
I have the below:
regexp_substr(My_Data, '(?<=id:).*(?=;)', 1, 1)
which gives me the below error:
Invalid regular expression: '(?<=id:).*(?=;)', no argument for repetition operator: ?
I'm trying to split key value pairs where I have
id:1234;
Look-behind is not supported in Snowflake's regexp.
However, you can use regular regexp groups for what you're trying to achieve:
select regexp_substr('Something,id=12345;Somethng', 'id=([^;]+);',1, 1, 'e');
-----------------------------------------------------------------------+
REGEXP_SUBSTR('SOMETHING,ID=12345;SOMETHNG', 'ID=([^;]+);',1, 1, 'E') |
-----------------------------------------------------------------------+
12345 |
-----------------------------------------------------------------------+
Note the 'e' argument for extraction, see the documentation.

Resources