             url,
             parent_id,
             sort,
-            project_id,
             TO_JSONB(id) AS path,
             1 AS depth,
             CAST(sort AS text) AS pos,
-            LPAD(CAST(sort AS text), 3, '0') AS sortpos
+            LPAD(CAST(sort AS text), 3, '0') AS sortpos,
+            project_id
         FROM
             page
         WHERE

CREATE INDEX ON tree (url);
CREATE INDEX ON tree (parent_id);
CREATE INDEX ON tree (sort);
CREATE INDEX ON tree (project_id);
CREATE INDEX ON tree USING GIN (path);
CREATE INDEX ON tree (depth);
CREATE INDEX ON tree (pos);
CREATE INDEX ON tree (sortpos);

-- -----------------------------------------------------------


    url,
    parent_id,
    sort,
    path,
    depth,
    pos,
    sortpos,
    project_id
FROM
    t
ORDER BY
