farakh-shahid
Posted on February 22, 2023
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
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');
To Create vertex and edge labels:
CREATE LABEL person;
CREATE LABEL knows (weight double);
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);
Final Step How we Query on Graph
MATCH (a:person)-[e:knows]->(b:person) WHERE e.weight > 0.6 RETURN a,b;
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:
Posted on February 22, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.