Index: includes/database/pgsql/schema.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/pgsql/schema.inc,v
retrieving revision 1.3
diff -u -p -r1.3 schema.inc
--- includes/database/pgsql/schema.inc	26 Nov 2008 13:42:25 -0000	1.3
+++ includes/database/pgsql/schema.inc	16 Dec 2008 20:37:10 -0000
@@ -84,12 +84,7 @@ class DatabaseSchema_pgsql extends Datab
       unset($spec['not null']);
     }
     if (!empty($spec['unsigned'])) {
-      if ($spec['type'] == 'serial') {
-        $sql .= " CHECK ($name >= 0)";
-      }
-      else {
-        $sql .= '_unsigned';
-      }
+      $sql .= " CHECK ($name >= 0)";
     }
 
     if (!empty($spec['length'])) {
@@ -125,6 +120,20 @@ class DatabaseSchema_pgsql extends Datab
       $map = $this->getFieldTypeMap();
       $field['pgsql_type'] = $map[$field['type'] . ':' . $field['size']];
     }
+    if (!empty($field['unsigned'])) {
+      // bump the column type up to make up for byte used to determine positive of negative 
+      if (!isset($map)) {
+        $map = $this->getFieldTypeMap();
+      }
+      switch ($field['pgsql_type']) {
+        case 'smallint':
+          $field['pgsql_type'] = $map['int:medium'];
+        break;
+        case 'int' :
+          $field['pgsql_type'] = $map['int:big'];
+        break;
+      }
+    }
     if ($field['type'] == 'serial') {
       unset($field['not null']);
     }
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.291
diff -u -p -r1.291 system.install
--- modules/system/system.install	3 Dec 2008 16:32:22 -0000	1.291
+++ modules/system/system.install	16 Dec 2008 20:37:10 -0000
@@ -289,23 +289,12 @@ function system_requirements($phase) {
  */
 function system_install() {
   if (db_driver() == 'pgsql') {
-    // We create some custom types and functions using global names instead of
+    // We create some functions using global names instead of
     // prefixing them like we do with table names. If this function is ever
     // called again (for example, by the test framework when creating prefixed
     // test databases), the global names will already exist. We therefore avoid
     // trying to create them again in that case.
 
-    // Create unsigned types.
-    if (!db_result(db_query("SELECT COUNT(*) FROM pg_constraint WHERE conname = 'int_unsigned_check'"))) {
-      db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
-    }
-    if (!db_result(db_query("SELECT COUNT(*) FROM pg_constraint WHERE conname = 'smallint_unsigned_check'"))) {
-      db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
-    }
-    if (!db_result(db_query("SELECT COUNT(*) FROM pg_constraint WHERE conname = 'bigint_unsigned_check'"))) {
-      db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
-    }
-
     // Create functions.
     db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
       \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\'
@@ -3143,6 +3132,34 @@ function system_update_7015() {
 }
 
 /**
+ * Remove custom datatype *_unsigned in postgres.
+ */
+function system_update_7016() {
+  //only run querys if the driver used is postgres
+  if (db_driver() != 'pgsql') return array();
+  $ret = array();
+  $result = db_query("SELECT c.relname AS table, a.attname AS field, pg_catalog.format_type(a.atttypid, a.atttypmod) AS type FROM pg_catalog.pg_attribute a LEFT JOIN pg_class c ON (c.oid =  a.attrelid) WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relkind = 'r' AND pg_catalog.format_type(a.atttypid, a.atttypmod) LIKE '%unsigned%'");
+  while ($row = db_fetch_object($result)) {
+    switch ($row->type) {
+      case 'smallint_unsigned':
+        $datatype = 'int';
+      break;
+      case 'int_unsigned':
+      case 'bigint_unsigned':
+      default:
+        $datatype = 'bigint';
+      break;
+    }
+   $ret[] = update_sql('ALTER TABLE {' . $row->table . '} ALTER COLUMN ' . $row->field . ' TYPE ' . $datatype); 
+   $ret[] = update_sql('ALTER TABLE {' . $row->table . '} ADD CHECK (' . $row->field . ' >= 0)');
+  }
+  $ret[] = update_sql('DROP DOMAIN smallint_unsigned');
+  $ret[] = update_sql('DROP DOMAIN int_unsigned');
+  $ret[] = update_sql('DROP DOMAIN bigint_unsigned');
+  return $ret;
+}
+
+/**
  * @} End of "defgroup updates-6.x-to-7.x"
  * The next series of updates should start at 8000.
  */
