Index: database/updates.inc
===================================================================
RCS file: /cvs/drupal/drupal/database/updates.inc,v
retrieving revision 1.207
diff -u -Ffunction -r1.207 updates.inc
--- database/updates.inc	3 Mar 2006 08:46:09 -0000	1.207
+++ database/updates.inc	4 Mar 2006 04:34:03 -0000
@@ -1,81 +1,106 @@
 <?php
 // $Id: updates.inc,v 1.207 2006/03/03 08:46:09 dries Exp $
 
+/**
+ * @file
+ *
+ * For DBMS specific queries, use the following switch statement:
+ * @verbatim
+ * switch ($GLOBALS['db_type']) {
+ *   case 'mysql':
+ *   case 'mysqli':
+ *     // Put MySQL code here...
+ *     break;
+ *   case 'pgsql':
+ *     // Put PostgreSQL code here...
+ *     break;
+ * }
+ * @endverbatim
+ *
+ * For queries that depend on a particular version of a database server,
+ * use version_compare() and $GLOBALS['db_server_version'], like this:
+ * @verbatim
+ * if(version_compare($GLOBALS['db_server_version'], '4.1.0', '<')) {
+ *   // whatever...
+ * }
+ * @endverbatim
+ *
+ * All MySQL CREATE TABLE statements put in after update 169 must have the
+ * "!40100 DEFAULT CHARACTER SET utf8" comment appended to the SQL statement.
+ *
+ * @see update.php
+ */
+
 function system_update_110() {
   $ret = array();
 
-  // TODO: needs PGSQL version
-  if ($GLOBALS['db_type'] == 'mysql') {
-    /*
-    ** Search
-    */
-
-    $ret[] = update_sql('DROP TABLE {search_index}');
-    $ret[] = update_sql("CREATE TABLE {search_index} (
-      word varchar(50) NOT NULL default '',
-      sid int(10) unsigned NOT NULL default '0',
-      type varchar(16) default NULL,
-      fromsid int(10) unsigned NOT NULL default '0',
-      fromtype varchar(16) default NULL,
-      score int(10) unsigned default NULL,
-      KEY sid (sid),
-      KEY fromsid (fromsid),
-      KEY word (word)
-      )");
-
-    $ret[] = update_sql("CREATE TABLE {search_total} (
-      word varchar(50) NOT NULL default '',
-      count int(10) unsigned default NULL,
-      PRIMARY KEY word (word)
-      )");
-
-
-    /*
-    ** Blocks
-    */
-
-    $ret[] = update_sql('ALTER TABLE {blocks} DROP path');
-    $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility tinyint(1) NOT NULL');
-    $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text NOT NULL');
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    /*
-    ** Search
-    */
-    $ret[] = update_sql('DROP TABLE {search_index}');
-    $ret[] = update_sql("CREATE TABLE {search_index} (
-      word varchar(50) NOT NULL default '',
-      sid integer NOT NULL default '0',
-      type varchar(16) default NULL,
-      fromsid integer NOT NULL default '0',
-      fromtype varchar(16) default NULL,
-      score integer default NULL
-      )");
-    $ret[] = update_sql("CREATE INDEX {search_index}_sid_idx on {search_index}(sid)");
-    $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_idx on {search_index}(fromsid)");
-    $ret[] = update_sql("CREATE INDEX {search_index}_word_idx on {search_index}(word)");
-
-    $ret[] = update_sql("CREATE TABLE {search_total} (
-      word varchar(50) NOT NULL default '' PRIMARY KEY,
-      count integer default NULL
-      )");
-
-
-    /*
-    ** Blocks
-    */
-    // Postgres can only drop columns since 7.4
-    #$ret[] = update_sql('ALTER TABLE {blocks} DROP path');
-
-    $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility smallint');
-    $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN visibility set default 0");
-    $ret[] = update_sql('UPDATE {blocks} SET visibility = 0');
-    $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN visibility SET NOT NULL');
-    $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text');
-    $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN pages set default ''");
-    $ret[] = update_sql("UPDATE {blocks} SET pages = ''");
-    $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN pages SET NOT NULL');
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      /*
+       * Search
+       */
+      $ret[] = update_sql('DROP TABLE {search_index}');
+      $ret[] = update_sql("CREATE TABLE {search_index} (
+        word varchar(50) NOT NULL default '',
+        sid int(10) unsigned NOT NULL default '0',
+        type varchar(16) default NULL,
+        fromsid int(10) unsigned NOT NULL default '0',
+        fromtype varchar(16) default NULL,
+        score int(10) unsigned default NULL,
+        KEY sid (sid),
+        KEY fromsid (fromsid),
+        KEY word (word))");
+      $ret[] = update_sql("CREATE TABLE {search_total} (
+        word varchar(50) NOT NULL default '',
+        count int(10) unsigned default NULL,
+        PRIMARY KEY word (word))");
+
+      /*
+       * Blocks
+       */
+      $ret[] = update_sql('ALTER TABLE {blocks} DROP path');
+      $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility tinyint(1) NOT NULL');
+      $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text NOT NULL');
+      break;
+
+    case 'pgsql':
+      /*
+       * Search
+       */
+      $ret[] = update_sql('DROP TABLE {search_index}');
+      $ret[] = update_sql("CREATE TABLE {search_index} (
+        word varchar(50) NOT NULL default '',
+        sid integer NOT NULL default '0',
+        type varchar(16) default NULL,
+        fromsid integer NOT NULL default '0',
+        fromtype varchar(16) default NULL,
+        score integer default NULL)");
+      $ret[] = update_sql("CREATE INDEX {search_index}_sid_idx on {search_index}(sid)");
+      $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_idx on {search_index}(fromsid)");
+      $ret[] = update_sql("CREATE INDEX {search_index}_word_idx on {search_index}(word)");
+
+      $ret[] = update_sql("CREATE TABLE {search_total} (
+        word varchar(50) NOT NULL default '' PRIMARY KEY,
+        count integer default NULL)");
 
+      /*
+       * Blocks
+       */
+      if (version_compare($GLOBALS['db_version'], '7.3', '>=')) {
+        // PostgreSQL only supports dropping columns since 7.3
+        $ret[] = update_sql('ALTER TABLE {blocks} DROP path');
+      }
+
+      $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility smallint');
+      $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN visibility set default 0");
+      $ret[] = update_sql('UPDATE {blocks} SET visibility = 0');
+      $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN visibility SET NOT NULL');
+      $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text');
+      $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN pages set default ''");
+      $ret[] = update_sql("UPDATE {blocks} SET pages = ''");
+      $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN pages SET NOT NULL');
+      break;
   }
 
   $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'");
@@ -90,11 +115,14 @@ function system_update_111() {
 
   $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'throttle_%'");
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql('ALTER TABLE {sessions} ADD PRIMARY KEY sid (sid)');
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql('ALTER TABLE {sessions} ADD UNIQUE(sid)');
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {sessions} ADD PRIMARY KEY sid (sid)');
+      break;
+    case 'pgsql':
+      $ret[] = update_sql('ALTER TABLE {sessions} ADD UNIQUE(sid)');
+      break;
   }
 
   return $ret;
@@ -103,19 +131,20 @@ function system_update_111() {
 function system_update_112() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("CREATE TABLE {flood} (
-      event varchar(64) NOT NULL default '',
-      hostname varchar(128) NOT NULL default '',
-      timestamp int(11) NOT NULL default '0'
-     );");
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("CREATE TABLE {flood} (
-      event varchar(64) NOT NULL default '',
-      hostname varchar(128) NOT NULL default '',
-      timestamp integer NOT NULL default 0
-     );");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {flood} (
+        event varchar(64) NOT NULL default '',
+        hostname varchar(128) NOT NULL default '',
+        timestamp int(11) NOT NULL default '0')");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE TABLE {flood} (
+        event varchar(64) NOT NULL default '',
+        hostname varchar(128) NOT NULL default '',
+        timestamp integer NOT NULL default 0)");
+      break;
   }
 
   return $ret;
@@ -124,26 +153,27 @@ function system_update_112() {
 function system_update_113() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql('ALTER TABLE {accesslog} ADD aid int(10) NOT NULL auto_increment, ADD PRIMARY KEY (aid)');
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("SELECT * INTO TEMPORARY {accesslog}_t FROM {accesslog}");
-    $ret[] = update_sql("DROP TABLE {accesslog}");
-    $ret[] = update_sql("CREATE TABLE {accesslog} (
-      aid serial,
-      title varchar(255) default NULL,
-      path varchar(255) default NULL,
-      url varchar(255) default NULL,
-      hostname varchar(128) default NULL,
-      uid integer default '0',
-      timestamp integer NOT NULL default '0'
-    )");
-    $ret[] = update_sql("INSERT INTO {accesslog} (title, path, url, hostname, uid, timestamp) SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}_t");
-
-    $ret[] = update_sql("DROP TABLE {accesslog}_t");
-    $ret[] = update_sql("CREATE INDEX {accesslog}_timestamp_idx ON {accesslog} (timestamp);");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {accesslog} ADD aid int(10) NOT NULL auto_increment, ADD PRIMARY KEY (aid)');
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("SELECT * INTO TEMPORARY {accesslog}_t FROM {accesslog}");
+      $ret[] = update_sql("DROP TABLE {accesslog}");
+      $ret[] = update_sql("CREATE TABLE {accesslog} (
+        aid serial,
+        title varchar(255) default NULL,
+        path varchar(255) default NULL,
+        url varchar(255) default NULL,
+        hostname varchar(128) default NULL,
+        uid integer default '0',
+        timestamp integer NOT NULL default '0')");
+      $ret[] = update_sql("INSERT INTO {accesslog} (title, path, url, hostname, uid, timestamp) SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}_t");
 
+      $ret[] = update_sql("DROP TABLE {accesslog}_t");
+      $ret[] = update_sql("CREATE INDEX {accesslog}_timestamp_idx ON {accesslog} (timestamp)");
+      break;
   }
 
   // Flush the menu cache:
@@ -154,23 +184,25 @@ function system_update_113() {
 
 function system_update_114() {
   $ret = array();
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("CREATE TABLE {queue} (
-      nid int(10) unsigned NOT NULL,
-      uid int(10) unsigned NOT NULL,
-      vote int(3) NOT NULL default '0',
-      PRIMARY KEY (nid, uid)
-     )");
-  }
-  else if ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("CREATE TABLE {queue} (
-      nid integer NOT NULL default '0',
-      uid integer NOT NULL default '0',
-      vote integer NOT NULL default '0',
-      PRIMARY KEY (nid, uid)
-    )");
-    $ret[] = update_sql("CREATE INDEX {queue}_nid_idx ON queue(nid)");
-    $ret[] = update_sql("CREATE INDEX {queue}_uid_idx ON queue(uid)");
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {queue} (
+        nid int(10) unsigned NOT NULL,
+        uid int(10) unsigned NOT NULL,
+        vote int(3) NOT NULL default '0',
+        PRIMARY KEY (nid, uid))");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE TABLE {queue} (
+        nid integer NOT NULL default '0',
+        uid integer NOT NULL default '0',
+        vote integer NOT NULL default '0',
+        PRIMARY KEY (nid, uid))");
+      $ret[] = update_sql("CREATE INDEX {queue}_nid_idx ON queue(nid)");
+      $ret[] = update_sql("CREATE INDEX {queue}_uid_idx ON queue(uid)");
+      break;
   }
 
   $result = db_query("SELECT nid, votes, score, users FROM {node}");
@@ -196,11 +228,19 @@ function system_update_114() {
     }
   }
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    // Postgres only supports dropping of columns since 7.4
-    $ret[] = update_sql("ALTER TABLE {node} DROP votes");
-    $ret[] = update_sql("ALTER TABLE {node} DROP score");
-    $ret[] = update_sql("ALTER TABLE {node} DROP users");
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      if (version_compare($GLOBALS['db_version'], '7.3', '<')) {
+        // PostgreSQL only supports dropping columns since 7.3
+        return $ret;
+      }
+      // this pgsql version can handle column drops, so fall through...
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {node} DROP votes");
+      $ret[] = update_sql("ALTER TABLE {node} DROP score");
+      $ret[] = update_sql("ALTER TABLE {node} DROP users");
+      break;
   }
 
   return $ret;
@@ -221,24 +261,30 @@ function system_update_116() {
 
 function system_update_117() {
   $ret = array();
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
-                         vid int(10) NOT NULL default '0',
-                         type varchar(16) NOT NULL default '',
-                         PRIMARY KEY (vid, type))");
-  }
-  else if ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
-                         vid serial,
-                         type varchar(16) NOT NULL default '',
-                          PRIMARY KEY (vid, type)) ");
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
+        vid int(10) NOT NULL default '0',
+        type varchar(16) NOT NULL default '',
+        PRIMARY KEY (vid, type))");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
+        vid serial,
+        type varchar(16) NOT NULL default '',
+        PRIMARY KEY (vid, type))");
+      break;
   }
+
   return $ret;
 }
 
 function system_update_118() {
   $ret = array();
   $node_types = array();
+
   $result = db_query('SELECT vid, nodes FROM {vocabulary}');
   while ($vocabulary = db_fetch_object($result)) {
     $node_types[$vocabulary->vid] = explode(',', $vocabulary->nodes);
@@ -248,9 +294,20 @@ function system_update_118() {
       db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vid, $type);
     }
   }
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {vocabulary} DROP nodes");
+
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      if (version_compare($GLOBALS['db_version'], '7.3', '<')) {
+        // PostgreSQL only supports dropping columns since 7.3
+        return $ret;
+      }
+      // this pgsql version can handle column drops, so fall through...
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {vocabulary} DROP nodes");
+      break;
   }
+
   return $ret;
 }
 
@@ -311,24 +368,27 @@ function system_update_121() {
 }
 
 function system_update_122() {
-
   $ret = array();
+
   $ret[] = update_sql("ALTER TABLE {blocks} ADD types text");
-  return $ret;
 
+  return $ret;
 }
 
 function system_update_123() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255) NOT NULL default ''");
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255)");
-    $ret[] = update_sql("UPDATE {vocabulary} SET module = ''");
-    $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET NOT NULL");
-    $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET DEFAULT ''");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255) NOT NULL default ''");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255)");
+      $ret[] = update_sql("UPDATE {vocabulary} SET module = ''");
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET NOT NULL");
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET DEFAULT ''");
+      break;
   }
 
   $ret[] = update_sql("UPDATE {vocabulary} SET module = 'taxonomy'");
@@ -340,39 +400,37 @@ function system_update_123() {
   return $ret;
 }
 
+/**
+ * Redo update_105, correctly creating node_comment_statistics.
+ */
 function system_update_124() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    // redo update_105, correctly creating node_comment_statistics
-    $ret[] = update_sql("DROP TABLE IF EXISTS {node_comment_statistics}");
-
-    $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
-      nid int(10) unsigned NOT NULL auto_increment,
-      last_comment_timestamp int(11) NOT NULL default '0',
-      last_comment_name varchar(60) default NULL,
-      last_comment_uid int(10) NOT NULL default '0',
-      comment_count int(10) unsigned NOT NULL default '0',
-      PRIMARY KEY (nid),
-      KEY node_comment_timestamp (last_comment_timestamp)
-      )");
-  }
-
-  else {
-    // also drop incorrectly named table for PostgreSQL
-    $ret[] = update_sql("DROP TABLE {node}_comment_statistics");
-
-    $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
-      nid integer NOT NULL,
-      last_comment_timestamp integer NOT NULL default '0',
-      last_comment_name varchar(60)  default NULL,
-      last_comment_uid integer NOT NULL default '0',
-      comment_count integer NOT NULL default '0',
-      PRIMARY KEY (nid)
-    )");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("DROP TABLE IF EXISTS {node_comment_statistics}");
+      $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
+        nid int(10) unsigned NOT NULL auto_increment,
+        last_comment_timestamp int(11) NOT NULL default '0',
+        last_comment_name varchar(60) default NULL,
+        last_comment_uid int(10) NOT NULL default '0',
+        comment_count int(10) unsigned NOT NULL default '0',
+        PRIMARY KEY (nid),
+        KEY node_comment_timestamp (last_comment_timestamp))");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("DROP TABLE {node}_comment_statistics");
+      $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
+        nid integer NOT NULL,
+        last_comment_timestamp integer NOT NULL default '0',
+        last_comment_name varchar(60)  default NULL,
+        last_comment_uid integer NOT NULL default '0',
+        comment_count integer NOT NULL default '0',
+        PRIMARY KEY (nid))");
 
-    $ret[] = update_sql("CREATE INDEX {node_comment_statistics}_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp);
-");
+      $ret[] = update_sql("CREATE INDEX {node_comment_statistics}_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp)");
+      break;
   }
 
   // initialize table
@@ -389,19 +447,21 @@ function system_update_124() {
 }
 
 function system_update_125() {
-  // Postgres only update.
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'pgsql') {
-
-    $ret[] = update_sql("CREATE OR REPLACE FUNCTION if(boolean, anyelement, anyelement) RETURNS anyelement AS '
-          SELECT CASE WHEN $1 THEN $2 ELSE $3 END;
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      // PostgreSQL only update.
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE OR REPLACE FUNCTION if(boolean, anyelement, anyelement) RETURNS anyelement AS '
+        SELECT CASE WHEN $1 THEN $2 ELSE $3 END;
         ' LANGUAGE 'sql'");
-
-    $ret[] = update_sql("CREATE FUNCTION greatest(integer, integer, integer) RETURNS integer AS '
-                          SELECT greatest($1, greatest($2, $3));
-                        ' LANGUAGE 'sql'");
-
+      $ret[] = update_sql("CREATE FUNCTION greatest(integer, integer, integer) RETURNS integer AS '
+        SELECT greatest($1, greatest($2, $3));
+        ' LANGUAGE 'sql'");
+      break;
   }
 
   return $ret;
@@ -417,23 +477,31 @@ function system_update_126() {
 
 function system_update_127() {
   $ret = array();
-  if ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("ALTER TABLE {poll} RENAME voters TO polled");
-  }
-  else if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {poll} CHANGE voters polled longtext");
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {poll} CHANGE voters polled longtext");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("ALTER TABLE {poll} RENAME voters TO polled");
+      break;
   }
+
   return $ret;
 }
 
 function system_update_128() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
+      break;
+    case 'pgsql':
+      $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
+      break;
   }
 
   return $ret;
@@ -442,11 +510,14 @@ function system_update_128() {
 function system_update_129() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {vocabulary} ADD tags tinyint(3) unsigned default '0' NOT NULL");
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    db_add_column($ret, 'vocabulary', 'tags', 'smallint', array('default' => 0, 'not null' => TRUE));
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD tags tinyint(3) unsigned default '0' NOT NULL");
+      break;
+    case 'pgsql':
+      db_add_column($ret, 'vocabulary', 'tags', 'smallint', array('default' => 0, 'not null' => TRUE));
+      break;
   }
 
   return $ret;
@@ -464,19 +535,22 @@   // is needed for the basic functioning
 function system_update_131() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {boxes} DROP INDEX title");
-    // Removed recreation of the index, which is not present in the db schema
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("ALTER TABLE {boxes} DROP CONSTRAINT {boxes}_title_key");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {boxes} DROP INDEX title");
+      // Removed recreation of the index, which is not present in the db schema
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("ALTER TABLE {boxes} DROP CONSTRAINT {boxes}_title_key");
+      break;
   }
 
   return $ret;
 }
 
 function system_update_132() {
-  /**
+  /*
    * PostgreSQL only update.
    */
   $ret = array();
@@ -486,10 +560,10 @@ function system_update_132() {
       $ret[] = update_sql('DROP TABLE {search_total}');
       $ret[] = update_sql("CREATE TABLE {search_total} (
         word varchar(50) NOT NULL default '',
-             count float default NULL)");
+        count float default NULL)");
       $ret[] = update_sql('CREATE INDEX {search_total}_word_idx ON {search_total}(word)');
 
-      /**
+      /*
        * Wipe the search index
        */
       include_once './modules/search.module';
@@ -505,19 +579,20 @@ function system_update_132() {
 function system_update_133() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("CREATE TABLE {contact} (
-      subject varchar(255) NOT NULL default '',
-      recipients longtext NOT NULL default '',
-      reply longtext NOT NULL default ''
-      )");
-    $ret[] = update_sql("ALTER TABLE {users} ADD login int(11) NOT NULL default '0'");
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    // Table {contact} is changed in update_143() so I have moved it's creation there.
-    // It was never created here for postgres because of errors.
-
-    db_add_column($ret, 'users', 'login', 'int', array('default' => 0, 'not null' => TRUE));
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {contact} (
+        subject varchar(255) NOT NULL default '',
+        recipients longtext NOT NULL default '',
+        reply longtext NOT NULL default '')");
+      $ret[] = update_sql("ALTER TABLE {users} ADD login int(11) NOT NULL default '0'");
+      break;
+    case 'pgsql':
+      // Table {contact} is changed in update_143() so I have moved it's creation there.
+      // It was never created here for PostgreSQL because of errors.
+      db_add_column($ret, 'users', 'login', 'int', array('default' => 0, 'not null' => TRUE));
+      break;
   }
 
   return $ret;
@@ -525,7 +600,20 @@ function system_update_133() {
 
 function system_update_134() {
   $ret = array();
-  $ret[] = update_sql('ALTER TABLE {blocks} DROP types');
+
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      if (version_compare($GLOBALS['db_version'], '7.3', '<')) {
+        // PostgreSQL only supports dropping columns since 7.3
+        return $ret;
+      }
+      // this pgsql version can handle column drops, so fall through...
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {blocks} DROP types');
+      break;
+  }
+
   return $ret;
 }
 
@@ -539,6 +627,7 @@ function system_update_135() {
 
     variable_del('update_135_done');
   }
+
   return array();
 }
 
@@ -546,19 +635,20 @@ function system_update_136() {
   $ret = array();
 
   switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {users} CHANGE COLUMN changed access int(11) NOT NULL default '0'");
+      break;
     case 'pgsql':
       $ret[] = update_sql("DROP INDEX {users}_changed_idx"); // We drop the index first because it won't be renamed
       $ret[] = update_sql("ALTER TABLE {users} RENAME changed TO access");
       $ret[] = update_sql("CREATE INDEX {users}_access_idx on {users}(access)"); // Re-add the index
       break;
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {users} CHANGE COLUMN changed access int(11) NOT NULL default '0'");
-      break;
   }
 
   $ret[] = update_sql('UPDATE {users} SET access = login WHERE login > created');
   $ret[] = update_sql('UPDATE {users} SET access = created WHERE access = 0');
+
   return $ret;
 }
 
@@ -566,12 +656,16 @@ function system_update_137() {
   $ret = array();
 
   if (!variable_get('update_137_done', FALSE)) {
-    if ($GLOBALS['db_type'] == 'mysql') {
-      $ret[] = update_sql("ALTER TABLE {locales_source} CHANGE location location varchar(255) NOT NULL default ''");
-    }
-    elseif ($GLOBALS['db_type'] == 'pgsql') {
-      db_change_column($ret, 'locales_source', 'location', 'location', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
+    switch ($GLOBALS['db_type']) {
+      case 'mysql':
+      case 'mysqli':
+        $ret[] = update_sql("ALTER TABLE {locales_source} CHANGE location location varchar(255) NOT NULL default ''");
+        break;
+      case 'pgsql':
+        db_change_column($ret, 'locales_source', 'location', 'location', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
+        break;
     }
+
     variable_del('update_137_done');
   }
 
@@ -580,21 +674,24 @@ function system_update_137() {
 
 function system_update_138() {
   $ret = array();
+
   // duplicate of update_97 which never got into the default database.* files.
   $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('node/feed', 'rss.xml')");
+
   return $ret;
 }
 
 function system_update_139() {
   $ret = array();
+
   switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      db_add_column($ret, 'accesslog', 'timer', 'int', array('not null' => TRUE, 'default' => 0));
-      break;
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {accesslog} ADD timer int(10) unsigned NOT NULL default '0'");
       break;
+    case 'pgsql':
+      db_add_column($ret, 'accesslog', 'timer', 'int', array('not null' => TRUE, 'default' => 0));
+      break;
   }
 
   return $ret;
@@ -603,12 +700,16 @@ function system_update_139() {
 function system_update_140() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX (src)");
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("CREATE INDEX {url_alias}_src_idx ON {url_alias}(src)");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX (src)");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE INDEX {url_alias}_src_idx ON {url_alias}(src)");
+      break;
   }
+
   return $ret;
 }
 
@@ -632,17 +733,20 @@   // is needed for the basic functioning
 function system_update_143() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {contact} CHANGE subject category VARCHAR(255) NOT NULL ");
-    $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (category)");
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    // Why the table is created here? See update_133().
-    $ret[] = update_sql("CREATE TABLE {contact} (
-      category varchar(255) NOT NULL default '',
-      recipients text NOT NULL default '',
-      reply text NOT NULL default '',
-      PRIMARY KEY (category))");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {contact} CHANGE subject category VARCHAR(255) NOT NULL ");
+      $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (category)");
+      break;
+    case 'pgsql':
+      // Why the table is created here? See update_133().
+      $ret[] = update_sql("CREATE TABLE {contact} (
+        category varchar(255) NOT NULL default '',
+        recipients text NOT NULL default '',
+        reply text NOT NULL default '',
+        PRIMARY KEY (category))");
+      break;
   }
 
   return $ret;
@@ -650,18 +754,23 @@ function system_update_143() {
 
 function system_update_144() {
   $ret = array();
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {node} CHANGE type type VARCHAR(32) NOT NULL");
-  }
-  elseif ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql("DROP INDEX {node}_type_idx"); // Drop indexes using "type" column
-    $ret[] = update_sql("DROP INDEX {node}_title_idx");
-    db_change_column($ret, 'node', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
-    // Let's recreate the indexes
-    $ret[] = update_sql("CREATE INDEX {node}_type_idx ON {node}(type)");
-    $ret[] = update_sql("CREATE INDEX {node}_title_type_idx ON {node}(title,type)");
-    $ret[] = update_sql("CREATE INDEX {node}_status_type_nid_idx ON {node}(status,type,nid)");
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {node} CHANGE type type VARCHAR(32) NOT NULL");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("DROP INDEX {node}_type_idx"); // Drop indexes using "type" column
+      $ret[] = update_sql("DROP INDEX {node}_title_idx");
+      db_change_column($ret, 'node', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
+      // Let's recreate the indexes
+      $ret[] = update_sql("CREATE INDEX {node}_type_idx ON {node}(type)");
+      $ret[] = update_sql("CREATE INDEX {node}_title_type_idx ON {node}(title,type)");
+      $ret[] = update_sql("CREATE INDEX {node}_status_type_nid_idx ON {node}(status,type,nid)");
+      break;
   }
+
   return $ret;
 }
 
@@ -677,15 +786,15 @@ function system_update_145() {
   $ret = array();
 
   switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      db_change_column($ret, 'blocks', 'region', 'region', 'varchar(64)', array('default' => "'left'", 'not null' => TRUE));
-      db_add_column($ret, 'blocks', 'theme', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
-      break;
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {blocks} CHANGE region region varchar(64) default 'left' NOT NULL");
       $ret[] = update_sql("ALTER TABLE {blocks} ADD theme varchar(255) NOT NULL default ''");
       break;
+    case 'pgsql':
+      db_change_column($ret, 'blocks', 'region', 'region', 'varchar(64)', array('default' => "'left'", 'not null' => TRUE));
+      db_add_column($ret, 'blocks', 'theme', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
+      break;
   }
 
   // Intialize block data for default theme
@@ -707,86 +816,88 @@ function system_update_145() {
 function system_update_146() {
   $ret = array();
 
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("CREATE TABLE {node_revisions}
-                                SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format
-                                FROM {node}");
-
-    $ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext");
-
-    $ret[] = update_sql("ALTER TABLE {node} ADD vid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {files} ADD vid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {book} ADD vid int(10) unsigned NOT NULL default '0'");
-    $ret[] = update_sql("ALTER TABLE {forum} ADD vid int(10) unsigned NOT NULL default '0'");
-
-    $ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY");
-    $ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY");
-    $ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY");
-
-    $ret[] = update_sql("UPDATE {node} SET vid = nid");
-    $ret[] = update_sql("UPDATE {forum} SET vid = nid");
-    $ret[] = update_sql("UPDATE {book} SET vid = nid");
-    $ret[] = update_sql("UPDATE {files} SET vid = nid");
-
-    $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)");
-    $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)");
-    $ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)");
-    $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)");
-    $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)");
-
-    $ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
-
-    $ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)");
-    $ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)");
-    $ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)");
-    $ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)");
-    $vid = db_next_id('{node}_nid');
-    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)");
-  }
-  else { // pgsql
-    $ret[] = update_sql("CREATE TABLE {node_revisions} (
-      nid integer NOT NULL default '0',
-      vid integer NOT NULL default '0',
-      uid integer NOT NULL default '0',
-      title varchar(128) NOT NULL default '',
-      body text NOT NULL default '',
-      teaser text NOT NULL default '',
-      log text NOT NULL default '',
-      timestamp integer NOT NULL default '0',
-      format int NOT NULL default '0',
-      PRIMARY KEY (vid))");
-    $ret[] = update_sql("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, timestamp, format)
-      SELECT nid, nid AS vid, uid, title, body, teaser, changed AS timestamp, format
-      FROM {node}");
-    $ret[] = update_sql('CREATE INDEX {node_revisions}_nid_idx ON {node_revisions}(nid)');
-    $ret[] = update_sql('CREATE INDEX {node_revisions}_uid_idx ON {node_revisions}(uid)');
-    $vid = db_next_id('{node}_nid');
-    $ret[] = update_sql("CREATE SEQUENCE {node_revisions}_vid_seq INCREMENT 1 START $vid");
-
-    db_add_column($ret, 'node',  'vid', 'int', array('not null' => TRUE, 'default' => 0));
-    db_add_column($ret, 'files', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
-    db_add_column($ret, 'book',  'vid', 'int', array('not null' => TRUE, 'default' => 0));
-    db_add_column($ret, 'forum', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
-
-    $ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT {book}_pkey");
-    $ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT {forum}_pkey");
-    $ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT {files}_pkey");
-
-    $ret[] = update_sql("UPDATE {node} SET vid = nid");
-    $ret[] = update_sql("UPDATE {forum} SET vid = nid");
-    $ret[] = update_sql("UPDATE {book} SET vid = nid");
-    $ret[] = update_sql("UPDATE {files} SET vid = nid");
-
-    $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY (vid)");
-    $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY (vid)");
-
-    $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
-
-    $ret[] = update_sql('CREATE INDEX {node}_vid_idx ON {node}(vid)');
-    $ret[] = update_sql('CREATE INDEX {forum}_nid_idx ON {forum}(nid)');
-    $ret[] = update_sql('CREATE INDEX {files}_fid_idx ON {files}(fid)');
-    $ret[] = update_sql('CREATE INDEX {files}_vid_idx ON {files}(vid)');
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {node_revisions}
+        SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format
+        FROM {node}");
+
+      $ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int(10) unsigned NOT NULL default '0'");
+      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext");
+
+      $ret[] = update_sql("ALTER TABLE {node} ADD vid int(10) unsigned NOT NULL default '0'");
+      $ret[] = update_sql("ALTER TABLE {files} ADD vid int(10) unsigned NOT NULL default '0'");
+      $ret[] = update_sql("ALTER TABLE {book} ADD vid int(10) unsigned NOT NULL default '0'");
+      $ret[] = update_sql("ALTER TABLE {forum} ADD vid int(10) unsigned NOT NULL default '0'");
+
+      $ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY");
+      $ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY");
+      $ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY");
+
+      $ret[] = update_sql("UPDATE {node} SET vid = nid");
+      $ret[] = update_sql("UPDATE {forum} SET vid = nid");
+      $ret[] = update_sql("UPDATE {book} SET vid = nid");
+      $ret[] = update_sql("UPDATE {files} SET vid = nid");
+
+      $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)");
+      $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)");
+      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)");
+      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)");
+      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)");
+
+      $ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
+
+      $ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)");
+      $ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)");
+      $ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)");
+      $ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)");
+      $vid = db_next_id('{node}_nid');
+      $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("CREATE TABLE {node_revisions} (
+        nid integer NOT NULL default '0',
+        vid integer NOT NULL default '0',
+        uid integer NOT NULL default '0',
+        title varchar(128) NOT NULL default '',
+        body text NOT NULL default '',
+        teaser text NOT NULL default '',
+        log text NOT NULL default '',
+        timestamp integer NOT NULL default '0',
+        format int NOT NULL default '0',
+        PRIMARY KEY  (nid,vid))");
+      $ret[] = update_sql("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, timestamp, format)
+        SELECT nid, nid AS vid, uid, title, body, teaser, changed AS timestamp, format
+        FROM {node}");
+      $ret[] = update_sql('CREATE INDEX {node_revisions}_uid_idx ON {node_revisions}(uid)');
+      $vid = db_next_id('{node}_nid');
+      $ret[] = update_sql("CREATE SEQUENCE {node_revisions}_vid_seq INCREMENT 1 START $vid");
+
+      db_add_column($ret, 'node',  'vid', 'int', array('not null' => TRUE, 'default' => 0));
+      db_add_column($ret, 'files', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
+      db_add_column($ret, 'book',  'vid', 'int', array('not null' => TRUE, 'default' => 0));
+      db_add_column($ret, 'forum', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
+
+      $ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT {book}_pkey");
+      $ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT {forum}_pkey");
+      $ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT {files}_pkey");
+
+      $ret[] = update_sql("UPDATE {node} SET vid = nid");
+      $ret[] = update_sql("UPDATE {forum} SET vid = nid");
+      $ret[] = update_sql("UPDATE {book} SET vid = nid");
+      $ret[] = update_sql("UPDATE {files} SET vid = nid");
+
+      $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY (vid)");
+      $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY (vid)");
+
+      $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
+
+      $ret[] = update_sql('CREATE INDEX {node}_vid_idx ON {node}(vid)');
+      $ret[] = update_sql('CREATE INDEX {forum}_nid_idx ON {forum}(nid)');
+      $ret[] = update_sql('CREATE INDEX {files}_fid_idx ON {files}(fid)');
+      $ret[] = update_sql('CREATE INDEX {files}_vid_idx ON {files}(vid)');
+      break;
   }
 
   // Move logs too.
@@ -795,11 +906,22 @@ function system_update_146() {
     db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $row->log, $row->nid);
   }
 
-  $ret[] = update_sql("ALTER TABLE {book} DROP log");
-  $ret[] = update_sql("ALTER TABLE {node} DROP teaser");
-  $ret[] = update_sql("ALTER TABLE {node} DROP body");
-  $ret[] = update_sql("ALTER TABLE {node} DROP format");
-  $ret[] = update_sql("ALTER TABLE {node} DROP revisions");
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      if (version_compare($GLOBALS['db_version'], '7.3', '<')) {
+        // PostgreSQL only supports dropping columns since 7.3
+        return $ret;
+      }
+      // this pgsql version can handle column drops, so fall through...
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {book} DROP log");
+      $ret[] = update_sql("ALTER TABLE {node} DROP teaser");
+      $ret[] = update_sql("ALTER TABLE {node} DROP body");
+      $ret[] = update_sql("ALTER TABLE {node} DROP format");
+      $ret[] = update_sql("ALTER TABLE {node} DROP revisions");
+      break;
+  }
 
   return $ret;
 }
@@ -807,9 +929,14 @@ function system_update_146() {
 function system_update_147() {
   $ret = array();
 
-  // this update is mysql only, pgsql should get it right in the first try.
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {node_revisions} DROP type");
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {node_revisions} DROP type");
+      break;
+    case 'pgsql':
+      // this update is mysql only, pgsql should get it right in the first try.
+      break;
   }
 
   return $ret;
@@ -820,13 +947,13 @@ function system_update_148() {
 
   // Add support for tracking users' session ids (useful for tracking anon users)
   switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      db_add_column($ret, 'accesslog', 'sid', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
-      break;
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {accesslog} ADD sid varchar(32) NOT NULL default ''");
       break;
+    case 'pgsql':
+      db_add_column($ret, 'accesslog', 'sid', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
+      break;
   }
 
   return $ret;
@@ -843,8 +970,6 @@ function system_update_149() {
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {files} ADD COLUMN description VARCHAR(255) NOT NULL DEFAULT ''");
       break;
-    default:
-      break;
   }
 
   return $ret;
@@ -866,29 +991,24 @@ function system_update_150() {
     case 'mysqli':
     case 'mysql':
       $ret[] = update_sql("CREATE TABLE {search_dataset} (
-                           sid int(10) unsigned NOT NULL default '0',
-                           type varchar(16) default NULL,
-                           data longtext NOT NULL,
-                           KEY sid_type (sid, type)
-                           )");
-
+        sid int(10) unsigned NOT NULL default '0',
+        type varchar(16) default NULL,
+        data longtext NOT NULL,
+        KEY sid_type (sid, type))");
       $ret[] = update_sql("CREATE TABLE {search_index} (
-                           word varchar(50) NOT NULL default '',
-                           sid int(10) unsigned NOT NULL default '0',
-                           type varchar(16) default NULL,
-                           fromsid int(10) unsigned NOT NULL default '0',
-                           fromtype varchar(16) default NULL,
-                           score float default NULL,
-                           KEY sid_type (sid, type),
-                           KEY from_sid_type (fromsid, fromtype),
-                           KEY word (word)
-                           )");
-
+        word varchar(50) NOT NULL default '',
+        sid int(10) unsigned NOT NULL default '0',
+        type varchar(16) default NULL,
+        fromsid int(10) unsigned NOT NULL default '0',
+        fromtype varchar(16) default NULL,
+        score float default NULL,
+        KEY sid_type (sid, type),
+        KEY from_sid_type (fromsid, fromtype),
+        KEY word (word))");
       $ret[] = update_sql("CREATE TABLE {search_total} (
-                           word varchar(50) NOT NULL default '',
-                           count float default NULL,
-                           PRIMARY KEY word (word)
-                           )");
+        word varchar(50) NOT NULL default '',
+        count float default NULL,
+        PRIMARY KEY word (word))");
       break;
     case 'pgsql':
       $ret[] = update_sql("CREATE TABLE {search_dataset} (
@@ -896,7 +1016,6 @@ function system_update_150() {
         type varchar(16) default NULL,
         data text NOT NULL default '')");
       $ret[] = update_sql("CREATE INDEX {search_dataset}_sid_type_idx ON {search_dataset}(sid, type)");
-
       $ret[] = update_sql("CREATE TABLE {search_index} (
         word varchar(50) NOT NULL default '',
         sid integer NOT NULL default '0',
@@ -913,9 +1032,8 @@ function system_update_150() {
         count float default NULL,
         PRIMARY KEY(word))");
       break;
-    default:
-      break;
   }
+
   return $ret;
 }
 
@@ -984,9 +1102,9 @@ function system_update_151() {
 
         $mid = db_next_id('{menu}_mid');
         $ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " .
-                             "VALUES ($mid, {$menus[$loop]['pid']}, '" . db_escape_string($link_path) .
-                             "', '" . db_escape_string($links['text'][$i]) .
-                             "', '" . db_escape_string($links['description'][$i]) . "', 0, 118)");
+          "VALUES ($mid, {$menus[$loop]['pid']}, '" . db_escape_string($link_path) .
+          "', '" . db_escape_string($links['text'][$i]) .
+          "', '" . db_escape_string($links['description'][$i]) . "', 0, 118)");
       }
     }
     // delete Secondary links if not populated.
@@ -1025,14 +1143,16 @@ function system_update_151() {
 function system_update_152() {
   $ret = array();
 
-  // Postgresql only update
   switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      $ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
-      break;
     case 'mysql':
     case 'mysqli':
+      // PostgreSQL only update
       break;
+    case 'pgsql':
+      if (version_compare($GLOBALS['db_version'], '7.3', '>=')) {
+        // PostgreSQL only supports dropping columns since 7.3
+        $ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
+      }
   }
 
   return $ret;
@@ -1040,7 +1160,14 @@ function system_update_152() {
 
 function system_update_153(){
   $ret = array();
+
   switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {contact} DROP PRIMARY KEY");
+      $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int(11) NOT NULL PRIMARY KEY auto_increment");
+      $ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE KEY category (category)");
+      break;
     case 'pgsql':
       $ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT {contact}_pkey");
       $ret[] = update_sql("CREATE SEQUENCE {contact}_cid_seq");
@@ -1048,37 +1175,37 @@ function system_update_153(){
       $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (cid)");
       $ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT {contact}_category_key UNIQUE (category)");
       break;
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {contact} DROP PRIMARY KEY");
-      $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int(11) NOT NULL PRIMARY KEY auto_increment");
-      $ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE KEY category (category)");
-      break;
   }
+
   return $ret;
 }
 
 function system_update_154() {
   $ret = array();
+
   switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      db_add_column($ret, 'contact', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0));
-      db_add_column($ret, 'contact', 'selected', 'smallint', array('not null' => TRUE, 'default' => 0));
-      break;
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN weight tinyint(3) NOT NULL DEFAULT 0");
       $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN selected tinyint(1) NOT NULL DEFAULT 0");
       break;
+    case 'pgsql':
+      db_add_column($ret, 'contact', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0));
+      db_add_column($ret, 'contact', 'selected', 'smallint', array('not null' => TRUE, 'default' => 0));
+      break;
   }
+
   return $ret;
 }
 
 function system_update_155() {
   $ret = array();
 
-  // Postgresql only update
   switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      // PostgreSQL only update
+      break;
     case 'pgsql':
       $ret[] = update_sql("DROP TABLE {cache}");
       $ret[] = update_sql("CREATE TABLE {cache} (
@@ -1087,13 +1214,9 @@ function system_update_155() {
         expire integer NOT NULL default '0',
         created integer NOT NULL default '0',
         headers text default '',
-        PRIMARY KEY (cid)
-        )");
+        PRIMARY KEY (cid))");
       $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache}(expire)");
       break;
-    case 'mysql':
-    case 'mysqli':
-      break;
   }
 
   return $ret;
@@ -1101,15 +1224,19 @@ function system_update_155() {
 
 function system_update_156() {
   $ret = array();
+
   $ret[] = update_sql("DELETE FROM {cache}");
   system_themes();
+
   return $ret;
 }
 
 function system_update_157() {
   $ret = array();
+
   $ret[] = update_sql("DELETE FROM {url_alias} WHERE src = 'node/feed' AND dst = 'rss.xml'");
   $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('rss.xml', 'node/feed')");
+
   return $ret;
 }
 
@@ -1122,7 +1249,6 @@ function system_update_158() {
       $ret[] = update_sql("ALTER TABLE {old_revisions} ADD done tinyint(1) NOT NULL DEFAULT 0");
       $ret[] = update_sql("ALTER TABLE {old_revisions} ADD INDEX (done)");
       break;
-
     case 'pgsql':
       db_add_column($ret, 'old_revisions', 'done', 'smallint', array('not null' => TRUE, 'default' => 0));
       $ret[] = update_sql('CREATE INDEX {old_revisions}_done_idx ON {old_revisions}(done)');
@@ -1222,14 +1348,24 @@ function system_update_159() {
     case 'mysql':
       $ret[] = update_sql("UPDATE {sequences} SET id = $vid WHERE name = '{node_revisions}_vid'");
       break;
-
     case 'pgsql':
       $ret[] = update_sql("SELECT setval('{node_revisions}_vid_seq', $vid)");
       break;
   }
 
   if (db_num_rows($result) < 20) {
-    $ret[] = update_sql('ALTER TABLE {old_revisions} DROP done');
+    switch ($GLOBALS['db_type']) {
+      case 'pgsql':
+        if (version_compare($GLOBALS['db_version'], '7.3', '<')) {
+          // PostgreSQL only supports dropping columns since 7.3
+          return $ret;
+        }
+        // this pgsql version can handle column drops, so fall through...
+      case 'mysql':
+      case 'mysqli':
+        $ret[] = update_sql('ALTER TABLE {old_revisions} DROP done');
+        break;
+    }
   }
   else {
     $ret['#finished'] = FALSE;
@@ -1247,21 +1383,25 @@ function system_update_160() {
       }
     }
   }
+
   return array();
 }
 
 function system_update_161() {
   variable_del('forum_icon_path');
+
   return array();
 }
 
 function system_update_162() {
   $ret = array();
 
-  // PostgreSQL only update
   switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      // PostgreSQL only update
+      break;
     case 'pgsql':
-
       $ret[] = update_sql('DROP INDEX {book}_parent');
       $ret[] = update_sql('CREATE INDEX {book}_parent_idx ON {book}(parent)');
 
@@ -1271,6 +1411,11 @@ function system_update_162() {
       $ret[] = update_sql('ALTER TABLE {filters} ALTER delta SET DEFAULT 0');
       $ret[] = update_sql('DROP INDEX {filters}_module_idx');
 
+      /*
+       * The next two statements will produce errors if upgrading directly
+       * from 4.5 to 4.7.  The indexes in question were added in 4.6's
+       * database.pgsql but not in the upgrade system.
+       */
       $ret[] = update_sql('DROP INDEX {locales_target}_lid_idx');
       $ret[] = update_sql('DROP INDEX {locales_target}_lang_idx');
       $ret[] = update_sql('CREATE INDEX {locales_target}_locale_idx ON {locales_target}(locale)');
@@ -1289,14 +1434,24 @@ function system_update_162() {
       $ret[] = update_sql('CREATE INDEX {sessions}_uid_idx ON {sessions}(uid)');
       $ret[] = update_sql('CREATE INDEX {sessions}_timestamp_idx ON {sessions}(timestamp)');
 
-      $ret[] = update_sql('ALTER TABLE {accesslog} DROP mask');
+      switch ($GLOBALS['db_type']) {
+        case 'pgsql':
+          if (version_compare($GLOBALS['db_version'], '7.3', '<')) {
+            // PostgreSQL only supports dropping columns since 7.3
+            return $ret;
+          }
+          // this pgsql version can handle column drops, so fall through...
+        case 'mysql':
+        case 'mysqli':
+          $ret[] = update_sql('ALTER TABLE {accesslog} DROP mask');
+          break;
+      }
 
       db_change_column($ret, 'accesslog', 'path', 'path', 'text');
       db_change_column($ret, 'accesslog', 'url', 'url', 'text');
       db_change_column($ret, 'watchdog', 'link', 'link', 'text', array('not null' => TRUE, 'default' => "''"));
       db_change_column($ret, 'watchdog', 'location', 'location', 'text', array('not null' => TRUE, 'default' => "''"));
       db_change_column($ret, 'watchdog', 'referer', 'referer', 'text', array('not null' => TRUE, 'default' => "''"));
-
       break;
   }
 
@@ -1305,9 +1460,17 @@ function system_update_162() {
 
 function system_update_163() {
   $ret = array();
-  if ($GLOBALS['db_type'] == 'mysql' || $GLOBALS['db_type'] == 'mysqli') {
-    $ret[] = update_sql('ALTER TABLE {cache} CHANGE data data LONGBLOB');
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {cache} CHANGE data data LONGBLOB');
+      break;
+    case 'pgsql':
+      // MySQL only update
+      break;
   }
+
   return $ret;
 }
 
@@ -1318,21 +1481,19 @@ function system_update_164() {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("CREATE TABLE {poll_votes} (
-          nid int(10) unsigned NOT NULL,
-          uid int(10) unsigned NOT NULL default 0,
-          hostname varchar(128) NOT NULL default '',
-          INDEX (nid),
-          INDEX (uid),
-          INDEX (hostname)
-      )");
+        nid int(10) unsigned NOT NULL,
+        uid int(10) unsigned NOT NULL default 0,
+        hostname varchar(128) NOT NULL default '',
+        INDEX (nid),
+        INDEX (uid),
+        INDEX (hostname))");
       break;
 
     case 'pgsql':
       $ret[] = update_sql("CREATE TABLE {poll_votes} (
-          nid int NOT NULL,
-          uid int NOT NULL default 0,
-          hostname varchar(128) NOT NULL default ''
-      )");
+        nid int NOT NULL,
+        uid int NOT NULL default 0,
+        hostname varchar(128) NOT NULL default '')");
       $ret[] = update_sql('CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)');
       $ret[] = update_sql('CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)');
       $ret[] = update_sql('CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)');
@@ -1353,7 +1514,18 @@ function system_update_164() {
     }
   }
 
-  $ret[] = update_sql('ALTER TABLE {poll} DROP polled');
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      if (version_compare($GLOBALS['db_version'], '7.3', '<')) {
+        // PostgreSQL only supports dropping columns since 7.3
+        return $ret;
+      }
+      // this pgsql version can handle column drops, so fall through...
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {poll} DROP polled');
+      break;
+  }
 
   return $ret;
 }
@@ -1363,6 +1535,7 @@ function system_update_165() {
   variable_set('cron_last', $cron_last);
   variable_del('drupal_cron_last');
   variable_del('ping_cron_last');
+
   return array();
 }
 
@@ -1385,14 +1558,12 @@ function system_update_166() {
         version varchar(35) NOT NULL default'',
         created int(11) NOT NULL default '0',
         changed int(11) NOT NULL default '0',
-        PRIMARY KEY (cid)
-      )");
+        PRIMARY KEY (cid))");
       $ret[] = update_sql("CREATE TABLE {client_system} (
         cid int(10) NOT NULL default '0',
         name varchar(255) NOT NULL default '',
         type varchar(255) NOT NULL default '',
-        PRIMARY KEY (cid,name)
-      )");
+        PRIMARY KEY (cid,name))");
       break;
 
     case 'pgsql':
@@ -1408,14 +1579,12 @@ function system_update_166() {
         version varchar(35) NOT NULL default'',
         created integer NOT NULL default '0',
         changed integer NOT NULL default '0',
-        PRIMARY KEY (cid)
-      )");
+        PRIMARY KEY (cid))");
       $ret[] = update_sql("CREATE TABLE {client_system} (
         cid integer NOT NULL,
         name varchar(255) NOT NULL default '',
         type varchar(255) NOT NULL default '',
-        PRIMARY KEY (cid,name)
-      )");
+        PRIMARY KEY (cid,name))");
       break;
   }
 
@@ -1452,7 +1621,7 @@ function system_update_169() {
   if ($GLOBALS['db_type'] == 'pgsql') {
     $encoding = db_result(db_query('SHOW server_encoding'));
     if (!in_array(strtolower($encoding), array('unicode', 'utf8'))) {
-      $msg = 'Your PostgreSQL database is set up with the wrong character encoding ('. $encoding .'). It is possible it will not work as expected. It is advised to recreate it with UTF-8/Unicode encoding. More information can be found in the <a href="http://www.postgresql.org/docs/7.4/interactive/multibyte.html">PostgreSQL documentation</a>.';
+      $msg = 'Your PostgreSQL database is set up with the wrong character encoding ('. $encoding .'). It is possible it will not work as expected. It is advised to recreate it with UTF-8/Unicode encoding. More information can be found in the <a href="http://www.postgresql.org/docs/current/interactive/multibyte.html">PostgreSQL documentation</a>.';
       watchdog('php', $msg, WATCHDOG_WARNING);
       drupal_set_message($msg, 'status');
     }
@@ -1491,7 +1660,7 @@ function _system_update_utf8($tables) {
       case 'mysqli':
         break;
       case 'mysql':
-        if (version_compare(mysql_get_server_info($GLOBALS['active_db']), '4.1.0', '<')) {
+        if (version_compare($GLOBALS['db_server_version'], '4.1.0', '<')) {
           return array();
         }
         break;
@@ -1499,15 +1668,6 @@ function _system_update_utf8($tables) {
         return array();
     }
 
-    // See if database uses UTF-8 already
-    global $db_url;
-    $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
-    $db_name = substr($url['path'], 1);
-    $result = db_fetch_array(db_query('SHOW CREATE DATABASE `%s`', $db_name));
-    if (preg_match('/utf8/i', array_pop($result))) {
-      return array();
-    }
-
     // Make list of tables to convert
     $_SESSION['update_utf8'] = $tables;
     // Keep track of total for progress bar
@@ -1528,31 +1688,34 @@ function _system_update_utf8($tables) {
 
   // Progress percentage
   $ret['#finished'] = 1 - (count($list) / $_SESSION['update_utf8_total']);
+
   return $ret;
 }
 
 function system_update_170() {
   if (!variable_get('update_170_done', false)) {
     switch ($GLOBALS['db_type']) {
-      case 'pgsql':
-        $ret = array();
-        db_change_column($ret, 'system', 'schema_version', 'schema_version', 'smallint', array('not null' => TRUE, 'default' => -1));
-        break;
-
       case 'mysql':
       case 'mysqli':
         db_query('ALTER TABLE {system} CHANGE schema_version schema_version smallint(3) not null default -1');
         break;
+      case 'pgsql':
+        $ret = array();
+        db_change_column($ret, 'system', 'schema_version', 'schema_version', 'smallint', array('not null' => TRUE, 'default' => -1));
+        break;
     }
     // Set schema version -1 (uninstalled) for disabled modules (only affects contrib).
     db_query('UPDATE {system} SET schema_version = -1 WHERE status = 0 AND schema_version = 0');
   }
+
   return array();
 }
 
 function system_update_171() {
   $ret = array();
+
   $ret[] = update_sql('DELETE FROM {users_roles} WHERE rid IN ('. DRUPAL_ANONYMOUS_RID. ', '. DRUPAL_AUTHENTICATED_RID. ')');
+
   return $ret;
 }
 
@@ -1583,6 +1746,7 @@ function system_update_172() {
     unset($_SESSION['system_update_172_max']);
     return array();
   }
+
   return array('#finished' => $_SESSION['system_update_172'] / $_SESSION['system_update_172_max']);
 }
 
@@ -1590,56 +1754,54 @@ function system_update_173() {
   $ret = array();
 
   switch ($GLOBALS['db_type']) {
-    case 'pgsql':
+    case 'mysqli':
+    case 'mysql':
       // create file_revisions table
       $ret[] = update_sql("CREATE TABLE {file_revisions} (
-        fid integer NOT NULL default 0,
-        vid integer NOT NULL default 0,
+        fid int(10) unsigned NOT NULL default 0,
+        vid int(10) unsigned NOT NULL default 0,
         description varchar(255) NOT NULL default '',
-        list smallint NOT NULL default 0,
-        PRIMARY KEY (fid, vid))");
-      $ret[] = update_sql("INSERT INTO {file_revisions} SELECT fid, vid, description, list FROM {files}");
+        list tinyint(1) unsigned NOT NULL default 0,
+        PRIMARY KEY (fid, vid)) /*!40100 DEFAULT CHARACTER SET utf8 */");
+      $ret[] = update_sql('INSERT INTO {file_revisions} SELECT fid, vid, description, list FROM {files}');
 
       // alter files table
       $ret[] = update_sql("CREATE TABLE {files_copy} AS SELECT * FROM {files}");
       $ret[] = update_sql("DROP TABLE {files}");
       $ret[] = update_sql("CREATE TABLE {files} (
-        fid SERIAL,
-        nid integer NOT NULL default 0,
+        fid int(10) unsigned NOT NULL default 0,
+        nid int(10) unsigned NOT NULL default 0,
         filename varchar(255) NOT NULL default '',
         filepath varchar(255) NOT NULL default '',
         filemime varchar(255) NOT NULL default '',
-        filesize integer NOT NULL default 0,
-        PRIMARY KEY (fid))");
-      $ret[] = update_sql("INSERT INTO {files} SELECT DISTINCT ON (fid) fid, nid, filename, filepath, filemime, filesize FROM {files_copy}");
-      $ret[] = update_sql("SELECT setval('{files}_fid_seq', max(fid)) FROM {files}");
+        filesize int(10) unsigned NOT NULL default 0,
+        PRIMARY KEY (fid)) /*!40100 DEFAULT CHARACTER SET utf8 */");
+      $ret[] = update_sql("INSERT IGNORE INTO {files} SELECT fid, nid, filename, filepath, filemime, filesize FROM {files_copy}");
       $ret[] = update_sql("DROP TABLE {files_copy}");
       break;
-    case 'mysqli':
-    case 'mysql':
+    case 'pgsql':
       // create file_revisions table
       $ret[] = update_sql("CREATE TABLE {file_revisions} (
-        fid int(10) unsigned NOT NULL default 0,
-        vid int(10) unsigned NOT NULL default 0,
+        fid integer NOT NULL default 0,
+        vid integer NOT NULL default 0,
         description varchar(255) NOT NULL default '',
-        list tinyint(1) unsigned NOT NULL default 0,
-        PRIMARY KEY (fid, vid)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-      $ret[] = update_sql('INSERT INTO {file_revisions} SELECT fid, vid, description, list FROM {files}');
+        list smallint NOT NULL default 0,
+        PRIMARY KEY (fid, vid))");
+      $ret[] = update_sql("INSERT INTO {file_revisions} SELECT fid, vid, description, list FROM {files}");
 
       // alter files table
       $ret[] = update_sql("CREATE TABLE {files_copy} AS SELECT * FROM {files}");
       $ret[] = update_sql("DROP TABLE {files}");
       $ret[] = update_sql("CREATE TABLE {files} (
-        fid int(10) unsigned NOT NULL default 0,
-        nid int(10) unsigned NOT NULL default 0,
+        fid SERIAL,
+        nid integer NOT NULL default 0,
         filename varchar(255) NOT NULL default '',
         filepath varchar(255) NOT NULL default '',
         filemime varchar(255) NOT NULL default '',
-        filesize int(10) unsigned NOT NULL default 0,
-        PRIMARY KEY (fid)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-      $ret[] = update_sql("INSERT IGNORE INTO {files} SELECT fid, nid, filename, filepath, filemime, filesize FROM {files_copy}");
+        filesize integer NOT NULL default 0,
+        PRIMARY KEY (fid))");
+      $ret[] = update_sql("INSERT INTO {files} SELECT DISTINCT ON (fid) fid, nid, filename, filepath, filemime, filesize FROM {files_copy}");
+      $ret[] = update_sql("SELECT setval('{files}_fid_seq', max(fid)) FROM {files}");
       $ret[] = update_sql("DROP TABLE {files_copy}");
       break;
   }
@@ -1657,6 +1819,7 @@ function system_update_174() {
   if ($order > 0) {
     variable_set('comment_default_order', $order - 1);
   }
+
   return array();
 }
 
