A
A
Ashot Takiev2015-11-11 14:40:52
PostgreSQL
Ashot Takiev, 2015-11-11 14:40:52

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);

, where the left and right borders of the node correspond to the rules for defining a nested set.
That is, the output will be something like
-- Данные:

    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  |

Can anyone suggest an idea?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
aol-nnov, 2015-11-11
@aol-nnov

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.

X
xaja, 2013-12-02
@dfoster

a.button2 {position:relative}
a.button2 img {position:absolute;left:0px;}

D
Dm4k, 2013-12-03
@Dm4k

There are actually several options.
You can make the picture a background without repetition, positioned as you like, and set the correct size of the button block.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question