I have table witch contains fields: id, parent_id, name (etc.)
i want to order this table in “tree travel order” ie.
id parent_id
1, 0
3, 1
5, 1
2, 0
8, 2
4, 0
9, 4
(…)
in short describe: take root node, append all children, take next root node append children etc.
By your description I assume you mean breadth-first order, which could be easly done using a WITH RECURSIVE query (PostgreSQL 8.4+):
You could also use depth-first order using the following SQL: