Skip to main content

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.

Default configuration​

The default configuration for AGE is set to use the PostgreSQL database engine. The database will be created with the following parameters:

  • POSTGRES_PASSWORD: The password for the PostgreSQL user. This is set to CGC specific app_token that you receive after creating the database.
  • POSTGRES_USER=admin: The user for the PostgreSQL database.
  • POSTGRES_DB=db: The name of the PostgreSQL database. This is set to the name you provided when creating the database.
  • POSTGRES_HOST_AUTH_METHOD=trust: Configures PostgreSQL to skip password verification for connections, trusting that authentication has already occurred at the system level. This is convenient for development but creates a significant security risk in production environments.

How to connect to the database​

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