Index: openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql,v
diff -u -r1.47 -r1.48
--- openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql	11 Dec 2003 21:39:52 -0000	1.47
+++ openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql	26 Jan 2004 15:39:45 -0000	1.48
@@ -1746,13 +1746,14 @@
 declare
      highest_version__package_key    alias for $1;
      v_version_id                    apm_package_versions.version_id%TYPE;
+     v_max_version                   varchar;
 begin
-     select version_id into v_version_id
-	from apm_package_version_info i 
-	where apm_package_version__sortable_version_name(version_name) = 
-             (select max(apm_package_version__sortable_version_name(v.version_name))
-	             from apm_package_version_info v where v.package_key = highest_version__package_key)
-	and package_key = highest_version__package_key;
+     select max(apm_package_version__sortable_version_name(v.version_name)) into v_max_version 
+       from apm_package_version_info v where v.package_key = highest_version__package_key;
+
+     select version_id into v_version_id from apm_package_version_info i 
+	where apm_package_version__sortable_version_name(version_name) = v_max_version and i.package_key = highest_version__package_key;
+
       if NOT FOUND then 
          return 0;
       else
