Index: includes/database.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/Attic/database.pgsql.inc,v
retrieving revision 1.68.2.3
diff -u -r1.68.2.3 database.pgsql.inc
--- includes/database.pgsql.inc	17 Nov 2008 10:31:41 -0000	1.68.2.3
+++ includes/database.pgsql.inc	29 Jan 2009 04:06:06 -0000
@@ -776,7 +776,10 @@
  *   The table to be altered.
  */
 function db_drop_primary_key(&$ret, $table) {
-  $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT {'. $table .'}_pkey');
+  $name = '{'. $table. '}_pkey';
+  if (db_index_exists($name)) {
+    $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT '.$name);
+  }
 }
 
 /**
@@ -809,7 +812,9 @@
  */
 function db_drop_unique_key(&$ret, $table, $name) {
   $name = '{'. $table .'}_'. $name .'_key';
-  $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT '. $name);
+  if (db_index_exists($name)) {
+    $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT '. $name);
+  }
 }
 
 /**
@@ -840,7 +845,26 @@
  */
 function db_drop_index(&$ret, $table, $name) {
   $name = '{'. $table .'}_'. $name .'_idx';
-  $ret[] = update_sql('DROP INDEX '. $name);
+  
+  // Version 8.2 introduced IF EXISTS clause
+  // @see http://www.postgresql.org/docs/8.1/static/sql-dropindex.html
+  // @see http://www.postgresql.org/docs/8.2/static/sql-dropindex.html 
+  if (version_compare(db_version(), '8.2') < 0) {
+    $ret[] = update_sql('DROP INDEX IF EXISTS '. $name);
+  }
+  else if (db_index_exists($name)) {
+    $ret[] = update_sql('DROP INDEX '. $name);
+  }
+}
+
+/**
+ * Checks if an index exists.
+ * 
+ * @param Index name
+ * @return TRUE if the given index exists otherwise FALSE.
+ */
+function db_index_exists($name) {
+  return db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '$name'"));
 }
 
 /**
