PostgreSQL: How to find the last descendant in a linear “ancestor-descendant” relationship
问题 I have the following DB structure: RELATIONSHIP_TABLE - id << primary key - id_ancestor << foreign key to the same table - id_entry << foreign key to "ENTRY_TABLE" ENTRY_TABLE - id - name ... The hierarchy in table " RELATIONSHIP_TABLE " is linear. That means a record can be at most ancestor of one other record. Examples: 1. record1 2. record2 <- record3 <- record4 3. record5 <- record7 <- record9 <- record12 Every record within a particular hierarchy has the same " id_entry ". Now, I would