Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH RECURSIVE folder_tree AS
- (
- SELECT
- folder_id, folder_name, parent_id, cast(folder_name as character varying(2048)) as full_path
- FROM
- p_folder
- WHERE
- parent_id IS NULL
- UNION ALL
- SELECT
- pf.folder_id, pf.folder_name, pf.parent_id, cast(ft.full_path || '/' || pf.folder_name as character varying(2048)) as full_path
- FROM
- p_folder AS pf INNER JOIN
- folder_tree AS ft ON pf.parent_id = ft.folder_id
- )
- SELECT
- folder_id,
- full_path
- FROM
- folder_tree
- ORDER BY
- full_path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement