Index: database/database.pgsql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.pgsql,v
retrieving revision 1.86
diff -u -r1.86 database.pgsql
--- database/database.pgsql	19 Sep 2004 13:28:11 -0000	1.86
+++ database/database.pgsql	19 Sep 2004 22:41:08 -0000
@@ -162,7 +162,7 @@
 
 CREATE TABLE cache (
   cid varchar(255) NOT NULL default '',
-  data bytea default '',
+  data text default '',
   expire integer NOT NULL default '0',
   created integer NOT NULL default '0',
   headers text default '',
@@ -197,6 +197,20 @@
 CREATE INDEX comments_nid_idx ON comments(nid);
 
 --
+-- Table structre for table 'node_last_comment'
+--
+
+CREATE TABLE node_comment_statistics (
+  nid integer NOT NULL,
+  cid integer NOT NULL default '0',
+  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)
+);
+
+--
 -- Table structure for directory
 --
 
@@ -799,3 +813,15 @@
   RETURN $1 || $2;
 END;
 ' LANGUAGE 'plpgsql';
+
+CREATE FUNCTION "if"(integer, text, text) RETURNS text AS '
+BEGIN
+  IF $1 THEN
+    RETURN $2;
+  END IF; 
+  IF NOT $1 THEN
+    RETURN $3;
+  END IF;
+END;
+' LANGUAGE 'plpgsql';
+
Index: database/updates.inc
===================================================================
RCS file: /cvs/drupal/drupal/database/updates.inc,v
retrieving revision 1.61
diff -u -r1.61 updates.inc
--- database/updates.inc	19 Sep 2004 13:28:11 -0000	1.61
+++ database/updates.inc	19 Sep 2004 22:42:26 -0000
@@ -1754,7 +1754,6 @@
 }
 
 function update_105() {
-  // TODO: needs PGSQL equivalent
   $ret = array();
 
   $shadowupdates = db_query("SELECT nid,tid FROM {forum} WHERE shadow=0");
@@ -1762,34 +1761,64 @@
     db_query("DELETE FROM {term_node} WHERE nid = %d AND tid <> %d", $shadowrecord->nid, $shadowrecord->tid);
   }
 
-  $ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
-  $ret[] = update_sql('ALTER TABLE {node} ADD INDEX node_status_type (status, type, nid)');
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
+    $ret[] = update_sql('ALTER TABLE {node} ADD INDEX node_status_type (status, type, nid)');
 
-  $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
-    nid int(10) unsigned NOT NULL auto_increment,
-    cid int(10) unsigned NOT NULL default '0',
-    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)
-    ) TYPE=MyISAM");
-  $ret[] = update_sql("INSERT INTO {node_comment_statistics} (nid, cid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, 0, n.created, NULL, n.uid, 0 FROM {node} n");
-
-  $ret[] = update_sql("CREATE TABLE {forum_conv_temp} (
-    nid int(10) unsigned NOT NULL default '0',
-    cid int(10) unsigned NOT NULL default '0',
-    comment_count int(10) unsigned NOT NULL default '0',
-    PRIMARY KEY (nid)
-    )");
+    $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
+      nid int(10) unsigned NOT NULL auto_increment,
+      cid int(10) unsigned NOT NULL default '0',
+      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)
+      ) TYPE=MyISAM");
+    $ret[] = update_sql("INSERT INTO {node_comment_statistics} (nid, cid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, 0, n.created, NULL, n.uid, 0 FROM {node} n");
+
+    $ret[] = update_sql("CREATE TABLE {forum_conv_temp} (
+      nid int(10) unsigned NOT NULL default '0',
+      cid int(10) unsigned NOT NULL default '0',
+      comment_count int(10) unsigned NOT NULL default '0',
+      PRIMARY KEY (nid)
+      )");
+
+    $ret[] = update_sql('INSERT INTO {forum_conv_temp} SELECT f.nid, MAX(c.cid), COUNT(c.nid) FROM {forum} f INNER JOIN {comments} c ON f.nid = c.nid WHERE c.status = 0 GROUP BY f.nid');
+
+    /* This would be faster but only works with MySQL 4.0.4 or higher
+    $ret[] = update_sql('UPDATE {node_comment_statistics} n, {forum_conv_temp} t, {comments} c SET n.comment_count = t.comment_count, n.last_comment_timestamp = c.timestamp, n.last_comment_name = c.name, n.last_comment_uid = c.uid, n.cid = t.cid WHERE t.cid = c.cid AND n.nid = t.nid');
+    */
+  }
+  else {
+    // PostgreSQL is incapable of dropping columns in all but the latest versions.
+    $ret[] = update_sql("CREATE INDEX {node}_status_type_idx ON {node} (status, type, nid)");
 
-  $ret[] = update_sql('INSERT INTO {forum_conv_temp} SELECT f.nid, MAX(c.cid), COUNT(c.nid) FROM {forum} f INNER JOIN {comments} c ON f.nid = c.nid WHERE c.status = 0 GROUP BY f.nid');
 
-  /* This would be faster but only works with MySQL 4.0.4 or higher
-  $ret[] = update_sql('UPDATE {node_comment_statistics} n, {forum_conv_temp} t, {comments} c SET n.comment_count = t.comment_count, n.last_comment_timestamp = c.timestamp, n.last_comment_name = c.name, n.last_comment_uid = c.uid, n.cid = t.cid WHERE t.cid = c.cid AND n.nid = t.nid');
-  */
+    $ret[] = update_sql("CREATE TABLE {node}_comment_statistics (
+      nid integer NOT NULL,
+      cid integer NOT NULL default '0',
+      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("SELECT f.nid, MAX(c.cid) as cid, COUNT(c.nid) as comment_count INTO TEMPORARY {forum_conv_temp} FROM {forum} f INNER JOIN {comments} c ON f.nid = c.nid WHERE c.status = 0 GROUP BY f.nid");
 
+    $ret[] = update_sql("CREATE FUNCTION \"if\"(integer, text, text) RETURNS text AS '
+      BEGIN
+        IF $1 THEN
+          RETURN $2;
+        END IF; 
+        IF NOT $1 THEN
+          RETURN $3;
+        END IF;
+      END;
+      ' LANGUAGE 'plpgsql'");
+  }
+  
   $commentupdates = db_query("SELECT t.nid, t.cid, t.comment_count, c.timestamp, c.name, c.uid FROM {forum_conv_temp} t INNER JOIN {comments} c ON t.cid = c.cid");
   while ($commentrecord = db_fetch_object($commentupdates)) {
     db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d, cid = %d WHERE nid = %d", $commentrecord->comment_count, $commentrecord->timestamp, $commentrecord->name, $commentrecord->uid, $commentrecord->cid, $commentrecord->nid);
@@ -1806,7 +1835,7 @@
     $ret[] = update_sql('ALTER TABLE {cache} ADD INDEX expire (expire)');
   }
   else if ($GLOBALS['db_type'] == 'pgsql') {
-    // TODO: needs PGSQL equivalent.
+    $ret[] = update_sql('CREATE INDEX {cache}_expire_idx ON {cache}(expire)');
   }
 
   $ret[] = update_sql('DELETE FROM {cache}');
Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.28
diff -u -r1.28 bootstrap.inc
--- includes/bootstrap.inc	16 Sep 2004 07:17:54 -0000	1.28
+++ includes/bootstrap.inc	19 Sep 2004 22:42:45 -0000
@@ -118,6 +118,9 @@
  */
 function cache_get($key) {
   $cache = db_fetch_object(db_query("SELECT data, created, headers FROM {cache} WHERE cid = '%s'", $key));
+  if (isset($cache->data)) {
+    $cache->data = db_decode_blob($cache->data);
+  }
   return isset($cache->data) ? $cache : 0;
 }
 
@@ -271,7 +274,7 @@
         header($header);
       }
 
-      print db_decode_blob($cache->data);
+      print $cache->data;
 
       // Call all init() and exit() hooks without including all modules.
       // Only use those hooks for critical operations.
Index: includes/database.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.pgsql.inc,v
retrieving revision 1.2
diff -u -r1.2 database.pgsql.inc
--- includes/database.pgsql.inc	9 Sep 2004 05:51:08 -0000	1.2
+++ includes/database.pgsql.inc	19 Sep 2004 22:42:55 -0000
@@ -23,7 +23,8 @@
 function db_connect($url) {
   $url = parse_url($url);
 
-  $conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'];
+  $conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];
+  $conn_string .= ($url['port']) ? ' port=' . $url['port'] : '';
   $connection = pg_connect($conn_string) or die(pg_last_error());
 
   return $connection;
@@ -263,7 +264,7 @@
  *  Encoded data.
  */
 function db_encode_blob($data) {
-  return pg_escape_bytea($data);
+  return addcslashes($data, "\0..\37\\");
 }
 
 /**
