Index: openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.0.0-5.1.0d1.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.0.0-5.1.0d1.sql,v
diff -u -r1.5 -r1.6
--- openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.0.0-5.1.0d1.sql	18 Feb 2004 11:10:31 -0000	1.5
+++ openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.0.0-5.1.0d1.sql	18 Feb 2004 17:02:58 -0000	1.6
@@ -732,8 +732,8 @@
         -- The old algorithm had tree_sortkeys start from zero for each different parent
 
         select max(tree_leaf_key_to_int(child.tree_sortkey)) into v_max_value 
-          from cr_items child,
-         where not exists (select 1 from cr_items parent where parent.item_id = child.parent_id);
+          from cr_items child
+         where child.parent_id not in (select item_id from cr_items);
     else 
         select max(tree_leaf_key_to_int(tree_sortkey)) into v_max_value 
           from cr_items 
@@ -800,7 +800,7 @@
 
                 select max(tree_leaf_key_to_int(tree_sortkey)) into v_max_value
                   from cr_items child
-                 where not exists (select 1 from cr_items parent where parent.item_id = child.parent_id);
+                 where child.parent_id not in (select item_id from cr_items);
             else 
                 select max(tree_leaf_key_to_int(tree_sortkey)) into v_max_value
                   from cr_items 
