Index: openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql,v diff -u -r1.47 -r1.48 --- openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql 7 Aug 2017 23:48:11 -0000 1.47 +++ openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql 15 Sep 2017 20:03:12 -0000 1.48 @@ -223,17 +223,14 @@ - select r.package_id, - r.folder_id as root_folder_id - from fs_root_folders r, - (select parent.item_id as folder_id - from cr_items parent, - cr_items children - where children.item_id = :folder_id - and children.tree_sortkey - between parent.tree_sortkey - and tree_right(parent.tree_sortkey)) t - where r.folder_id = t.folder_id + With RECURSIVE items AS ( + select cr.item_id from cr_items cr where cr.item_id = :folder_id + UNION ALL + select cr.parent_id from cr_items cr, items where items.item_id = cr.item_id + ) + select r.package_id, r.folder_id as root_folder_id + from items i, fs_root_folders r + where r.folder_id = i.item_id