Answer the question
In order to leave comments, you need to log in
How to display ltree in PostgreSQL nested set?
Good afternoon.
There is a table with an ltree structure and it needs to be converted to a nested set.
StructureLtree(id INT PRIMARY KEY, value TEXT, path ltree);
-- Данные:
pk | value | path |
0 | 'A' | '' |
0 | 'B' | '1' |
0 | 'C' | '2' |
0 | 'D' | '1.3' |
0 | 'E' | '1.4' |
0 | 'F' | '1.5' |
0 | 'G' | '2.6' |
0 | 'H' | '2.7' |
StructureSets(id INT PRIMARY KEY, value TEXT, lft INT, rgt INT);
-- Данные:
pk | value | lft | rgt |
0 | 'A' | 1 | 16 |
1 | 'B' | 2 | 9 |
2 | 'C' | 10 | 15 |
3 | 'D' | 3 | 4 |
4 | 'E' | 5 | 6 |
5 | 'F' | 7 | 8 |
6 | 'G' | 11 | 12 |
7 | 'H' | 13 | 14 |
Answer the question
In order to leave comments, you need to log in
There is a cool guy on the Internet - Bill Karwin. He wrote about stacking different trees into relational tables.
And he also has a book "SQL Antipatterns. Avoiding the Pitfalls of Database Programming" there is also about trees.
a.button2 {position:relative}
a.button2 img {position:absolute;left:0px;}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question