Skip to content

Calculate "on-the-fly" auxiliar tree structure when using PostgreSQL as a source #1

@FacundoAdorno

Description

@FacundoAdorno

When using the --database-info as a children data source, the following "tree" is constructed programatically in a hard-coded way:

-- insert level 0
insert into tree
SELECT handle, id, name, cant, CONCAT('.', id,'.'), CONCAT('.', handle,'.'), depth
FROM cant_per_com cp
WHERE depth = 0;
-- insert level 1
insert into tree
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth
--SELECT handle, name, CONCAT(handle), cant, depth
FROM cant_per_com cp
INNER JOIN tree t on cp.handle_padre = t.handle
WHERE cp.depth = 1 -- and cp.handle = '10915/41'
ORDER BY cp.handle_padre, cp.handle;
-- insert level 2
insert into tree
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth
FROM cant_per_com cp
INNER JOIN tree t on cp.handle_padre = t.handle
WHERE cp.depth = 2
ORDER BY cp.handle_padre, cp.handle;
-- insert level 3
insert into tree
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth
FROM cant_per_com cp
INNER JOIN tree t on cp.handle_padre = t.handle
WHERE cp.depth = 3
ORDER BY cp.handle_padre, cp.handle;
-- insert level 4
insert into tree
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth
FROM cant_per_com cp
INNER JOIN tree t on cp.handle_padre = t.handle
WHERE cp.depth = 4
ORDER BY cp.handle_padre, cp.handle;

Try to get the max depth stored in this table

CREATE TEMPORARY TABLE cant_per_com AS (

and generate the auxiliar "tree" based on this calculated depth.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions