Skip to content

A docker container for AgensGraph extension (AGE)

Notifications You must be signed in to change notification settings

mattcburns/docker-agensgraph-extension

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Personal fork for managing my own version of this container with latest release.

Docker Apache AGE for Postgres

This is an image to build the Apache AGE on the official PostgreSQL 13 Docker image.

Running the container

It can be run by executing:

docker run -it -e POSTGRES_PASSWORD=mypassword -p {HostPort}:5432 ghcr.io/mattcburns/docker-agensgraph-extension/agensgraph-extension

In the above command, replace {HostPort} with a port you'd like to forward to, or remove the -p flag altogether if you want to run psql from inside the container.

Loading AGE

Connect to your containerized Postgres instance, for example:

psql -h 0.0.0.0 -p {HostPort} -U postgres

Then run the following commands:

CREATE EXTENSION age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;

Using AGE

First you will need to create a graph:

SELECT create_graph('my_graph_name');

To execute Cypher queries, you will need to wrap them in the following syntax:

SELECT * from cypher('my_graph_name', $$
  CypherQuery
$$) as (a agtype);

For example, if we wanted to create a graph with 4 nodes, we could do something as shown below:

SELECT * from cypher('my_graph_name', $$
  CREATE (a:Part {part_num: '123'}),
         (b:Part {part_num: '345'}),
         (c:Part {part_num: '456'}),
         (d:Part {part_num: '789'})
$$) as (a agtype);

--- RESULTS
 a
---
(0 rows)

Then we could query the graph with the following:

SELECT * from cypher('my_graph_name', $$
  MATCH (a)
  RETURN a
$$) as (a agtype);

--- RESULTS
                                          a
-------------------------------------------------------------------------------------
 {"id": 844424930131969, "label": "Part", "properties": {"part_num": "123"}}::vertex
 {"id": 844424930131970, "label": "Part", "properties": {"part_num": "345"}}::vertex
 {"id": 844424930131971, "label": "Part", "properties": {"part_num": "456"}}::vertex
 {"id": 844424930131972, "label": "Part", "properties": {"part_num": "789"}}::vertex
(4 rows)

Next, we could create a relationship between a couple of nodes:

SELECT * from cypher('my_graph_name', $$
  MATCH (a:Part {part_num: '123'}), (b:Part {part_num: '345'})
  CREATE (a)-[u:used_by { quantity: 1 }]->(b)
$$) as (a agtype);

--- RESULTS
 a
---
(0 rows)

Next we can return the path we just created (results have been formatted for readability):

SELECT * from cypher('my_graph_name', $$
  MATCH p=(a)-[]-(b)
  RETURN p
$$) as (a agtype);
// RESULTS
// ROW 1
[
   {
      "id":844424930131969,
      "label":"Part",
      "properties":{
         "part_num":"123"
      }
   }::"vertex",
   {
      "id":1125899906842625,
      "label":"used_by",
      "end_id":844424930131970,
      "start_id":844424930131969,
      "properties":{
         "quantity":1
      }
   }::"edge",
   {
      "id":844424930131970,
      "label":"Part",
      "properties":{
         "part_num":"345"
      }
   }::"vertex"
]::"path"
// ROW 2
[
   {
      "id":844424930131970,
      "label":"Part",
      "properties":{
         "part_num":"345"
      }
   }::"vertex",
   {
      "id":1125899906842625,
      "label":"used_by",
      "end_id":844424930131970,
      "start_id":844424930131969,
      "properties":{
         "quantity":1
      }
   }::"edge",
   {
      "id":844424930131969,
      "label":"Part",
      "properties":{
         "part_num":"123"
      }
   }::"vertex"
]::"path"
(2 rows)

About

A docker container for AgensGraph extension (AGE)

Resources

Stars

Watchers

Forks

Languages

  • Dockerfile 100.0%