Index: DatabasePostgres.php
===================================================================
--- DatabasePostgres.php	(revision 25929)
+++ DatabasePostgres.php	(working copy)
@@ -1148,7 +1148,7 @@
 	}
 
 	function encodeBlob( $b ) {
-		return pg_escape_bytea( $b );
+		return new Blob( pg_escape_bytea( $b ) );
 	}
 	function decodeBlob( $b ) {
 		return pg_unescape_bytea( $b );
@@ -1161,11 +1161,10 @@
 	function addQuotes( $s ) {
 		if ( is_null( $s ) ) {
 			return 'NULL';
-		} else if (is_array( $s )) { ## Assume it is bytea data
-			return "E'$s[1]'";
+		} else if ($s instanceof Blob) {
+			return "'$s'";
 		}
 		return "'" . pg_escape_string($s) . "'";
-		// Unreachable: return "E'" . pg_escape_string($s) . "'";
 	}
 
 	function quote_ident( $s ) {
Index: Database.php
===================================================================
--- Database.php	(revision 25928)
+++ Database.php	(working copy)
@@ -36,6 +36,22 @@
 };
 
 /**
+ * Utility class
+ * @addtogroup Database
+ *
+ * This allows us to treat blobs different from a regular string when needed.
+ */
+class Blob {
+	var $data;
+	function __construct($data) {
+		$this->mData = $data;
+	}
+	function __toString() {
+		return $this->mData;
+	}
+};
+
+/**
  * Utility class.
  * @addtogroup Database
  */
@@ -1543,6 +1559,9 @@
 			} else {
 				$first = false;
 			}
+			if ( $value instanceof Blob ) {
+				$value = $value->__toString();
+			}
 			if ( ($mode == LIST_AND || $mode == LIST_OR) && is_numeric( $field ) ) {
 				$list .= "($value)";
 			} elseif ( ($mode == LIST_SET) && is_numeric( $field ) ) {
