Index: openacs-4/packages/acs-tcl/tcl/apm-install-procs-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-install-procs-oracle.xql,v
diff -u -r1.21 -r1.22
--- openacs-4/packages/acs-tcl/tcl/apm-install-procs-oracle.xql	7 Aug 2017 23:47:59 -0000	1.21
+++ openacs-4/packages/acs-tcl/tcl/apm-install-procs-oracle.xql	25 Sep 2017 17:59:21 -0000	1.22
@@ -296,17 +296,6 @@
   </querytext>
 </fullquery>
 
-<fullquery name="apm_package_upgrade_p.apm_package_upgrade_p">      
-      <querytext>
-      
-	select apm_package_version.version_name_greater(:version_name, version_name) upgrade_p
-	from apm_package_versions
-	where package_key = :package_key
-	and version_id = apm_package.highest_version (:package_key)
-    
-      </querytext>
-</fullquery>
-
 <fullquery name="apm_package_upgrade_from.apm_package_upgrade_from">      
       <querytext>
       
Index: openacs-4/packages/acs-tcl/tcl/apm-install-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-install-procs-postgresql.xql,v
diff -u -r1.21 -r1.22
--- openacs-4/packages/acs-tcl/tcl/apm-install-procs-postgresql.xql	7 Aug 2017 23:47:59 -0000	1.21
+++ openacs-4/packages/acs-tcl/tcl/apm-install-procs-postgresql.xql	25 Sep 2017 17:59:21 -0000	1.22
@@ -211,17 +211,6 @@
   </querytext>
 </fullquery>
 
-<fullquery name="apm_package_upgrade_p.apm_package_upgrade_p">      
-      <querytext>
-      
-	select apm_package_version__version_name_greater(:version_name, version_name) as upgrade_p
-	from apm_package_versions
-	where package_key = :package_key
-	and version_id = apm_package__highest_version (:package_key)
-    
-      </querytext>
-</fullquery>
-
 <fullquery name="apm_version_enable.apm_package_version_enable">      
       <querytext>
 
Index: openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl,v
diff -u -r1.110 -r1.111
--- openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl	7 Aug 2017 23:47:59 -0000	1.110
+++ openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl	25 Sep 2017 17:59:21 -0000	1.111
@@ -1638,7 +1638,12 @@
     @return 1 if a version of the indicated package_key of version lower than version_name \
         is already installed in the system, 0 otherwise.
 } {
-    return [db_string apm_package_upgrade_p {} -default 0]
+    set package_version_name [apm_highest_version_name $package_key]
+    if {$package_version_name eq ""} {
+        return 0
+    } else {
+        return [expr {[apm_version_names_compare $package_version_name $version_name] == -1}]
+    }
 }
 
 ad_proc -private apm_package_upgrade_from { package_key version_name } {