Live data from Hacker News

Representing Graphs in PostgreSQL

richard-towers.com

1–10 of 80 posts

Re: Representing Graphs in PostgreSQL

#7
post #2

There is also https://age.apache.org/ , an extension to facilitate graph queries in postgresql.

Glad they used Cypher. One of the best and most intuitive query languages I've used personally.

Yeah Cypher was so good and made everything so intuitive. Loved working with Neo4J for a prototype and then had to face the licensing issues and huge costs and had to abandon it.

Re: Representing Graphs in PostgreSQL

#8
Im a big fan of GraphDatabase's since about 10 years. I even wrote my own "in memory graph storage" in golang for a specific use case that none of the big GraphDatabase's could cover at the time.

That said - i WISH people would embrase the existing GraphDatabases more and make the hosters support them as standard, rather than abusing existing relational databases for graph purposes.

And to make it clear,i'm not talking about my own experimental one, i mean stuff like Neo4j, OrientDB etc.

Re: Representing Graphs in PostgreSQL

#9
ltree is the one I ended up using. I don't like it much. The way it works allows you to setup a tree but you can't easily move things around within a tree once they're in.

I forgot to say that it's also obviously only a tree, not a graph. It's still useful for some cases.

It has a very good way of querying which is probably fast if you have very deep trees but in the end we didn't need the deep trees so it was chosen for the wrong reasons.

https://www.postgresql.org/docs/current/ltree.html

You essentially have a path field in your record which lists the ids of all the records that are parents of the current one plus the current one.

e.g. if your records are regions of the world and the id is the country name then the path might look like this:

Earth.Europe.Poland

There is support for queries like "what are all the descendants of Europe"

    SELECT name FROM regions WHERE path 
Or you can use matching:

    SELECT name FROM regions WHERE path ~ '*.Europe.*';

Re: Representing Graphs in PostgreSQL

#10
post #7

Earlier quoted context omitted.

Glad they used Cypher. One of the best and most intuitive query languages I've used personally.

Yeah Cypher was so good and made everything so intuitive. Loved working with Neo4J for a prototype and then had to face the licensing issues and huge costs and had to abandon it.

I got bitten by the same, we were looking at switching to memgraph (which is also Cypher, but C++ rather than Java), sadly abandoned for other reasons ...
Post reply on HN