I’m trying to create a graph database from an existing relational database. So a little background information is that I have a tbale with product numbers and serial numbers and I want a graph database that illustrates their relations. I have a tree like structure in the product numbers, that’s why I want to make a graph database with the apache AGE.
I have managed to run the command:
SELECT * FROM ag_catalog.create_graph('part_numbers_graph');
But when I run:
INSERT INTO part_numbers_graph
SELECT agtype(format('{"id": %L, "label": "SSN", "properties": {"name": %L}}', SSN, SSN)::jsonb)
FROM serial_table;
I get the following error:
relation "part_numbers_graph" does not exist
I have ran the command:
SELECT * FROM ag_catalog.ag_graph;
I can see that the graph is there.
graphid | name | namespace
---------+--------------------+--------------------
32924 | part_numbers_graph | part_numbers_graph
I have succesfully been able to run both
CREATE EXTENSION age;
and
LOAD 'age';
When I run
pg_config
I can see that I have installed
VERSION = PostgreSQL 12.14 (Ubuntu 12.14-1.pgdg22.04+1)
2
Answers
part_numbers_graph
is not a regular Postgres table, but a graph table which stores data in the form of vertices and edges and requires data to be inserted usingcypher
queries.For more information above
cypher
queries, see the official Apache AGE documentation.For your particular example, a cypher query would look something like:
To insert values into a graph you should use the cypher function.
For example in your case the query will look something like this :
With this query you create a node that has
SSN
label and has 2 property fieldsid
andname
. Age has its own way to createid's
though so maybe you don’t have to actually hard code your ownid
in the query and just let age keep track of theid's
of the different nodes and edges.