What is the recommended way to create a graph from a table (or from an SQL query, in general)?
Say, we have a table A with fields id
and parent_id
, where the latter refers back to the former of some row.
How would I go about and cast this into an AGE graph easily?
Ideally, this would be without doing a client-server roundtrip of first querying table rows and then creating the corresponding graph vertices and edges.
Currently, there seems to be a way to load graphs from CSV files (https://age.apache.org/age-manual/master/intro/agload.html), but this doesn’t really help in this case.
Also, there seems to be a helper function written in plpython available (https://github.com/sorrell/age-compose/blob/master/docker-entrypoint/initdb.d/20-initgraph.sql#L10-L37), but this isn’t ideal either.
2
Answers
I think you have to do manually. I don’t believe that it’s too much work, the graph doesn’t hold columns, the nodes through labels and properties do. So you create the graph and then create the CSV file and load them through the methods you posted.
If you prefer a manual approach without relying on CSV files or utilities, you can create the nodes and edges directly within the graph database. I think it’s the best way to solve it.