共计 1604 个字符,预计需要花费 5 分钟才能阅读完成。
编译装置
# root 下
useradd agens
mkdir -p /usr/local/agens
chown -R agens:agens /usr/local/agens/
# agens 下
git clone https://github.com/bitnine-oss/agensgraph.git
# --prefix 指定装置目录
./configure --prefix=/usr/local/agens
make
make install
初始化启动数据库
initdb -D /home/agens/work/data/agens
# 批改端口号
echo 'port = 5462' >> /home/agens/work/data/agens/postgresql.conf
ag_ctl start -D /home/agens/work/data/agens
# 官网文档说默认创立的库同以后用户,即 agens,# 然而我试验创立的是 postgres 库
# 登陆默认库
agens -d postgres -p 5462
# 创立新库
createdb agens -p 5462
# 登陆新库
agens -d agens -p 5462
简略应用
# graph_path,相似于 schema
# 默认为空,session 级别,创立后,主动赋值给 graph_path
CREATE GRAPH network;
SET graph_path = network;
# 创立顶点(vertice),边(edge)CREATE VLABEL person;
CREATE ELABEL knows;
# 创立点及边
CREATE (:person {name: 'Tom'})-[:knows {fromdate:'2011-11-24'}]->(:person {name: 'Summer'});
CREATE (:person {name: 'Pat'})-[:knows {fromdate:'2013-12-25'}]->(:person {name: 'Nikki'});
CREATE (:person {name: 'Olive'})-[:knows {fromdate:'2015-01-26'}]->(:person {name: 'Todd'});
MATCH (p:Person {name: 'Tom'}),(k:Person{name: 'Pat'})
CREATE (p)-[:KNOWS {fromdate:'2017-02-27'} ]->(k);
生成图如下:
查问
#
MATCH (n:person {name: 'Tom'})-[:knows]->(m:person) RETURN n.name AS n, m.name AS m;
n | m
-------+----------
"Tom" | "Summer"
"Tom" | "Pat"
(2 rows)
MATCH (p:person {name: 'Tom'})-[:knows]->(f:person)
RETURN f.name
UNION ALL
MATCH (p:person {name: 'Tom'})-[:knows]->()-[:knows]->(f:person)
RETURN f.name;
name
----------
"Summer"
"Pat"
"Nikki"
(3 rows)
MATCH (p:person {name: 'Tom'})-[r:knows*1..2]->(f:person)
RETURN f.name, r[1].fromdate;
name | fromdate
----------+--------------
"Summer" |
"Pat" |
"Nikki" | "2013-12-25"
(3 rows)
参考资料:
https://github.com/bitnine-os…
https://cdn.modb.pro/wiki/4440
https://www.jianshu.com/p/bc6…
http://bitnine.net/documentat…
正文完
发表至: postgresql
2022-12-19