Initial scenario
My software uses a tree data structure, and I store it in SQL. I use the abstraction called Adjacency List which consists of each row storing ID
and ParentID
.
ID
is Primary Key and ParentID
is a Foreign Key to the same table.
The problem
I want to "convert" my SQL abstraction to Path Enumeration. It consists of each row storing ID
and a varchar
field storing the path of the IDs, from the root to the current row. For example, the Path
field of the row with ID = 6
in this tree:
Would be /1/2/4/6/
. More details here, by the name Lineage Column.
Question
How do I build a column Path
from an existing database that only has ID
and ParentID
?