Index: openacs-4/packages/bookmarks/sql/postgresql/bookmarks-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/bookmarks/sql/postgresql/bookmarks-create.sql,v
diff -u -r1.17 -r1.18
--- openacs-4/packages/bookmarks/sql/postgresql/bookmarks-create.sql	8 Dec 2001 01:17:59 -0000	1.17
+++ openacs-4/packages/bookmarks/sql/postgresql/bookmarks-create.sql	9 Dec 2001 04:21:58 -0000	1.18
@@ -107,6 +107,13 @@
 -- With index on tree_sortkey
 create index bm_bookmarks_idx1 on bm_bookmarks(tree_sortkey);
 
+create function bm_bookmarks_get_tree_sortkey(integer) returns varbit as '
+declare
+  p_bookmark_id    alias for $1;
+begin
+  return tree_sortkey from bm_bookmarks where bookmark_id = p_bookmark_id;
+end;' language 'plpgsql';
+
 create function bm_bookmarks_insert_tr () returns opaque as '
 declare
         v_parent_sk     varbit default null;
@@ -721,10 +728,9 @@
 	SELECT CASE WHEN count(*)=0 THEN ''f'' ELSE ''t'' END INTO v_private_p
 	FROM acs_objects, 
 	(
-		SELECT bm2.bookmark_id FROM bm_bookmarks bm, bm_bookmarks bm2
-		WHERE bm.bookmark_id = p_bookmark_id
-                  and bm.tree_sortkey between bm2.tree_sortkey and tree_right(bm2.tree_sortkey)
-                  and tree_ancestor_p(bm2.tree_sortkey, bm.tree_sortkey)
+		SELECT bm.bookmark_id FROM bm_bookmarks bm,
+                  (SELECT tree_ancestor_keys(bm_bookmarks_get_tree_sortkey(p_bookmark_id)) as tree_sortkey) parents
+		WHERE bm.tree_sortkey = parents.tree_sortkey
 	) b
 	WHERE b.bookmark_id = acs_objects.object_id
 	AND acs_objects.security_inherit_p = ''f'';
