AGE
Apache AGE is an extension for PostgreSQL that enbales users to leverage a graph database on top of the existing relational databases. As an extension of PostgreSQL, AGE supports all the functonalities and features of PostgreSQL while also offering a graph model to boot.
How to run?​
Running on CGC is very easy. You just need to create a new database and load the AGE extension.
cgc db create -n <database_name> pg-age
After creating the database, you will receive an app token to your database.
How to connect to the database​
You can connect to the database from any notebook running in your namespace with CGC SDK.
import cgc.sdk as cgc
postgresql = cgc.postgresql_client("<database_name>","<app_token>")
For more information about CGC SDK and how to connect to the database, please refer to our docs
Installation​
For every connection of AGE you start, you will need to load the AGE extension.
CREATE EXTENSION age;
LOAD age;
SET search_path = ag_catalog, "$user", public;
Done! You can now use AGE in your database.
Example usage​
To create a graph, use the create_graph function located in the ag_catalog namespace.
SELECT create_graph('graph_name');
To create a single vertex with label and properties, use the CREATE clause.
SELECT *
FROM cypher('graph_name', $$
CREATE (:label {property:"Node A"})
$$) as (v agtype);
SELECT *
FROM cypher('graph_name', $$
CREATE (:label {property:"Node B"})
$$) as (v agtype);
To create an edge between two nodes and set its properties:
SELECT *
FROM cypher('graph_name', $$
MATCH (a:label), (b:label)
WHERE a.property = 'Node A' AND b.property = 'Node B'
CREATE (a)-[e:RELTYPE {property:a.property + '<->' + b.property}]->(b)
RETURN e
$$) as (e agtype);
And to query the connected nodes:
SELECT * from cypher('graph_name', $$
MATCH (V)-[R]-(V2)
RETURN V,R,V2
$$) as (V agtype, R agtype, V2 agtype);
For more information about AGE, please refer to the official documentation and Github repository