I have a tree structure in a sql table, for example:
CREATE TABLE containers (
container_id serial NOT NULL PRIMARY KEY,
parent integer REFERENCES containers (container_id))
Now I want to determine the order between nodes with the same parent.
I thought about adding a column node_indexto ORDER BY, but this seems to be suboptimal, since this is due to the modification of the index of a large number of nodes when the structure changes.
This may include adding, removing, reordering, or moving nodes from one subtree to another.
Is there an sql data type for ordered sequence or an efficient way to simulate? No need to be fully standard sql, I just need a solution for mssqland hopefullypostgresql
EDITTo be clear, the order is arbitrary. In fact, the user will be able to drag the tree nodes in the graphical interface
source
share