News for hackers. Stuff that matters.
Re:Hierarchical Structures in PostgreSQL (2020) by codingclaws on Friday June 25, 2021 @03:43PM (#27635366)
Peaches 'n' Stink [1] uses ltree for nested comments. All the PostgreSQL is here [2]. The first query that uses ltree is on line 452 [3].

It was hard to decide on the ltree "path" format. There's a "path" value for each comment and it is what sets up the hierarchy. What I ended up using was this (root level comments):

1.aaa

1.aab

1.aac

1.aad

.

.

.

1.aaz

1.aba

1.abb

The "1" is the post ID. Sub-comments under the first comment above would be:

1.aaa.aaa

1.aaa.aab

1.aaa.aac

The reason why I used this "path" format is because if I sort alphabetically then the comments will be in the correct "vertical" order to display chronologically.

[1] https://www.peachesnstink.com

[2] https://github.com/ferg1e/peaches-n-stink/blob/master/db/ind...

[3] https://github.com/ferg1e/peaches-n-stink/blob/master/db/ind...

There are no comments on this comment yet.