DEV Community

Cover image for What is Graph in Apache AGE Part 2
farakh-shahid
farakh-shahid

Posted on

What is Graph in Apache AGE Part 2

For part 1 here

In previous Post I write about what is graph database in depth.I would recommend to study it.

How we create Graph in Apache AGE. AGE is extension in postgreSQL for graph database functionality.

Create a Graph

To create a graph, use the create_graph function, located in the ag_catalog namespace.

Syntax: create_graph(graph_name);

Returns:

void
Enter fullscreen mode Exit fullscreen mode

image

Considerations

This function will not return any results. The graph is created if there is no error message.

Tables needed to set up the graph are automatically created.

Example:

SELECT * FROM ag_catalog.create_graph('graph_name');
Enter fullscreen mode Exit fullscreen mode

To Create vertex and edge labels:

CREATE LABEL person;
CREATE LABEL knows (weight double);

Enter fullscreen mode Exit fullscreen mode

How we insert data into Graph:

INSERT INTO person VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie');
INSERT INTO knows VALUES (1, 2, 0.8), (1, 3, 0.5), (2, 3, 0.6);

Enter fullscreen mode Exit fullscreen mode

Final Step How we Query on Graph

MATCH (a:person)-[e:knows]->(b:person) WHERE e.weight > 0.6 RETURN a,b;

Enter fullscreen mode Exit fullscreen mode

Delete a Graph

To delete a graph, use the drop_graph function, located in the ag_catalog namespace.

Syntax: drop_graph(graph_name, cascade);

References:

  1. https://age.apache.org/age-manual/master/intro/graphs.html
  2. https://www.fabiomarini.net/postgresql-with-apache-age-playing-more-seriously-with-graph-databases/
  3. https://bitnine.net/blog-about-bitnine/blog-press/age-postgresql-extension-graph-database-functionality/?ckattempt=1

Top comments (0)