Good afternoon, I can not figure out what the problem is, trying to build a tree. The request itself works only until the time when there are no more than 10 Structural Subdivisions when everything is less, everything is OK, when everything moves more, could you tell me what I'm doing wrong? Here is my query and table schema.
WITH RECURSIVE Rec(DeptKod, PKod, DeptName, Path, Level) AS( SELECT DeptKod, PKod, cast(DeptName AS VARCHAR) AS DeptName, cast(DeptKod AS VARCHAR) AS Path,1 FROM Structural_Subdivision WHERE PKod IS NULL UNION SELECT D.DeptKod, D.PKod, lpad(' ', 3*level) || D.DeptName,Path || cast(D.DeptKod AS VARCHAR), Level+1 FROM Structural_Subdivision D INNER JOIN Rec R ON (D.PKod = R.DeptKod)) SELECT DeptKod, DeptName FROM Rec ORDER BY Path; 