Hacker News new | ask | show | jobs
by bokwoon 1780 days ago
For modelling trees, I much prefer using a list of ancestors compared to the parent-child adjacency list because it doesn't require recursion to answer basic questions. I had thought about how I would model threaded comments in SQL some time ago and wrote down an example of what I mean:

https://gist.github.com/bokwoon95/4fd34a78e72b2935e78ec0f40e...

1 comments

This data structure you used is covered by the native postgres data type "ltree" right?

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

  "This module implements a data type ltree for representing labels of data stored in a hierarchical tree-like structure. Extensive facilities for searching through label trees are provided."