diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c
index 6fae89cad57c4a8be66b375bb9d1b936fc8e0e16..c3f45e1afa7add95f3051a1b93654f581bfe27f7 100644
--- a/contrib/btree_gin/btree_gin.c
+++ b/contrib/btree_gin/btree_gin.c
@@ -1,5 +1,5 @@
 /*
- * $PostgreSQL: pgsql/contrib/btree_gin/btree_gin.c,v 1.2 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gin/btree_gin.c,v 1.3 2009/08/04 18:49:50 tgl Exp $
  */
 #include "postgres.h"
 
@@ -8,6 +8,7 @@
 #include "fmgr.h"
 #include "access/skey.h"
 #include "utils/builtins.h"
+#include "utils/bytea.h"
 #include "utils/cash.h"
 #include "utils/date.h"
 #include "utils/inet.h"
diff --git a/contrib/btree_gin/expected/bytea.out b/contrib/btree_gin/expected/bytea.out
index 7b191492056fe3826f4e4614ceed2e252cbce666..8b5a0c615d46f0fb2977a3f88aa9a23b60ed78e7 100644
--- a/contrib/btree_gin/expected/bytea.out
+++ b/contrib/btree_gin/expected/bytea.out
@@ -1,4 +1,6 @@
 set enable_seqscan=off;
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 CREATE TABLE test_bytea (
 	i bytea
 );
diff --git a/contrib/btree_gin/sql/bytea.sql b/contrib/btree_gin/sql/bytea.sql
index 96be56bf65d9e6c8ff84dc25e679d0e8a17bcbe9..0ef6247e10df15c69988e0f574a2b6cb08ade49e 100644
--- a/contrib/btree_gin/sql/bytea.sql
+++ b/contrib/btree_gin/sql/bytea.sql
@@ -1,4 +1,6 @@
 set enable_seqscan=off;
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 
 CREATE TABLE test_bytea (
 	i bytea
diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c
index 3c5a2e0ce5b33a2ddfde0788e43efa09610ae937..f78134f443d3cc8bc787b8b1a518e4aef4585339 100644
--- a/contrib/btree_gist/btree_bit.c
+++ b/contrib/btree_gist/btree_bit.c
@@ -1,9 +1,9 @@
 /*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_bit.c,v 1.10 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_bit.c,v 1.11 2009/08/04 18:49:50 tgl Exp $
  */
 #include "btree_gist.h"
 #include "btree_utils_var.h"
-#include "utils/builtins.h"
+#include "utils/bytea.h"
 #include "utils/varbit.h"
 
 
diff --git a/contrib/btree_gist/btree_bytea.c b/contrib/btree_gist/btree_bytea.c
index 9977b201c6a999c230735bbd6e5ff2602322dba0..88b4a380e89998c4935bcbc35f253eadfb6b5142 100644
--- a/contrib/btree_gist/btree_bytea.c
+++ b/contrib/btree_gist/btree_bytea.c
@@ -1,9 +1,9 @@
 /*
- * $PostgreSQL: pgsql/contrib/btree_gist/btree_bytea.c,v 1.9 2009/06/11 14:48:50 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gist/btree_bytea.c,v 1.10 2009/08/04 18:49:50 tgl Exp $
  */
 #include "btree_gist.h"
 #include "btree_utils_var.h"
-#include "utils/builtins.h"
+#include "utils/bytea.h"
 
 
 /*
diff --git a/contrib/citext/expected/citext.out b/contrib/citext/expected/citext.out
index 34ce3da3ee5c1b3adfee4cbedeb3ea98bf0c2071..21e73be2d75feb1e92cf6a3c154f5d8eed64e3e2 100644
--- a/contrib/citext/expected/citext.out
+++ b/contrib/citext/expected/citext.out
@@ -737,18 +737,6 @@ SELECT 'f'::citext::"char" = 'f'::"char" AS t;
  t
 (1 row)
 
-SELECT 'foo'::bytea::citext = 'foo' AS t;
- t 
----
- t
-(1 row)
-
-SELECT 'foo'::citext::bytea = 'foo'::bytea AS t;
- t 
----
- t
-(1 row)
-
 SELECT '100'::money::citext = '$100.00' AS t;
  t 
 ---
diff --git a/contrib/citext/expected/citext_1.out b/contrib/citext/expected/citext_1.out
index cc03e234ed209ea81042d9875b22ae0eb56c5a62..5fa537bc198105b06082ed0006ebf8db28270ef8 100644
--- a/contrib/citext/expected/citext_1.out
+++ b/contrib/citext/expected/citext_1.out
@@ -737,18 +737,6 @@ SELECT 'f'::citext::"char" = 'f'::"char" AS t;
  t
 (1 row)
 
-SELECT 'foo'::bytea::citext = 'foo' AS t;
- t 
----
- t
-(1 row)
-
-SELECT 'foo'::citext::bytea = 'foo'::bytea AS t;
- t 
----
- t
-(1 row)
-
 SELECT '100'::money::citext = '$100.00' AS t;
  t 
 ---
diff --git a/contrib/citext/sql/citext.sql b/contrib/citext/sql/citext.sql
index 52999c2e634040fc83010fa3ab616125b7056648..9014e5d931a8863b312a0018737c9c3bbde9dd21 100644
--- a/contrib/citext/sql/citext.sql
+++ b/contrib/citext/sql/citext.sql
@@ -226,9 +226,6 @@ SELECT 'f'::citext::char = 'f'::char AS t;
 SELECT 'f'::"char"::citext = 'f' AS t;
 SELECT 'f'::citext::"char" = 'f'::"char" AS t;
 
-SELECT 'foo'::bytea::citext = 'foo' AS t;
-SELECT 'foo'::citext::bytea = 'foo'::bytea AS t;
-
 SELECT '100'::money::citext = '$100.00' AS t;
 SELECT '100'::citext::money = '100'::money AS t;
 
diff --git a/contrib/pgcrypto/expected/blowfish.out b/contrib/pgcrypto/expected/blowfish.out
index 5c09cf5cd9446bc91b4ba23b33b97e4f0f7c2177..86c3244cece7ec459062a47bfb42111ba0bfb450 100644
--- a/contrib/pgcrypto/expected/blowfish.out
+++ b/contrib/pgcrypto/expected/blowfish.out
@@ -1,6 +1,8 @@
 --
 -- Blowfish cipher
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 -- some standard Blowfish testvalues
 SELECT encode(encrypt(
 decode('0000000000000000', 'hex'),
diff --git a/contrib/pgcrypto/expected/init.out b/contrib/pgcrypto/expected/init.out
index 6a5710d5a1fc887c21bd0dbb68df2c76ffb57db4..4cb108199752f50559631b148bdc40638983ecad 100644
--- a/contrib/pgcrypto/expected/init.out
+++ b/contrib/pgcrypto/expected/init.out
@@ -8,6 +8,8 @@
 SET client_min_messages = warning;
 \set ECHO none
 RESET client_min_messages;
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 -- check for encoding fn's
 SELECT encode('foo', 'hex');
  encode 
diff --git a/contrib/pgcrypto/expected/pgp-armor.out b/contrib/pgcrypto/expected/pgp-armor.out
index 1655f13318061d8acd13249ecc81ba9d2310d0ce..1bb24615965cd8fb6c08493aa98d7e3d91a7d1b4 100644
--- a/contrib/pgcrypto/expected/pgp-armor.out
+++ b/contrib/pgcrypto/expected/pgp-armor.out
@@ -1,50 +1,52 @@
 --
 -- PGP Armor
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 select armor('');
             armor            
 -----------------------------
  -----BEGIN PGP MESSAGE-----
-                            
- =twTO                      
- -----END PGP MESSAGE-----  
-                            
+ 
+ =twTO
+ -----END PGP MESSAGE-----
+ 
 (1 row)
 
 select armor('test');
             armor            
 -----------------------------
  -----BEGIN PGP MESSAGE-----
-                            
- dGVzdA==                   
- =+G7Q                      
- -----END PGP MESSAGE-----  
-                            
+ 
+ dGVzdA==
+ =+G7Q
+ -----END PGP MESSAGE-----
+ 
 (1 row)
 
 select dearmor(armor(''));
  dearmor 
 ---------
-        
+ 
 (1 row)
 
 select dearmor(armor('zooka'));
  dearmor 
 ---------
- zooka  
+ zooka
 (1 row)
 
 select armor('0123456789abcdef0123456789abcdef0123456789abcdef
 0123456789abcdef0123456789abcdef0123456789abcdef');
                                     armor                                     
 ------------------------------------------------------------------------------
- -----BEGIN PGP MESSAGE-----                                                 
-                                                                             
+ -----BEGIN PGP MESSAGE-----
+ 
  MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmCjAxMjM0NTY3
- ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1Njc4OWFiY2RlZg==                    
- =JFw5                                                                       
- -----END PGP MESSAGE-----                                                   
-                                                                             
+ ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1Njc4OWFiY2RlZg==
+ =JFw5
+ -----END PGP MESSAGE-----
+ 
 (1 row)
 
 -- lots formatting
@@ -60,7 +62,7 @@ em9va2E=
 -----END PGP MESSAGE-----');
  dearmor 
 ---------
- zooka  
+ zooka
 (1 row)
 
 -- lots messages
@@ -88,7 +90,7 @@ d3Jvbmc=
 ');
  dearmor 
 ---------
- right  
+ right
 (1 row)
 
 -- bad crc
diff --git a/contrib/pgcrypto/expected/pgp-encrypt.out b/contrib/pgcrypto/expected/pgp-encrypt.out
index 637b4738378e197c148cd1222091eeb93579f77b..8ef3875fd68ce07f3c20309476bb5700281969f8 100644
--- a/contrib/pgcrypto/expected/pgp-encrypt.out
+++ b/contrib/pgcrypto/expected/pgp-encrypt.out
@@ -1,6 +1,8 @@
 --
 -- PGP encrypt
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'), 'key');
  pgp_sym_decrypt 
 -----------------
diff --git a/contrib/pgcrypto/expected/pgp-pubkey-encrypt.out b/contrib/pgcrypto/expected/pgp-pubkey-encrypt.out
index e222541c24c8b2e463380bd4f37ce30929ecc31e..df2756c4d0620cede4ee36f2de2c550fc45035fb 100644
--- a/contrib/pgcrypto/expected/pgp-pubkey-encrypt.out
+++ b/contrib/pgcrypto/expected/pgp-pubkey-encrypt.out
@@ -1,6 +1,8 @@
 --
 -- PGP Public Key Encryption
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 -- successful encrypt/decrypt
 select pgp_pub_decrypt(
 	pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
diff --git a/contrib/pgcrypto/expected/rijndael.out b/contrib/pgcrypto/expected/rijndael.out
index cb336e335d4674ceadb204e6d17d18abc16356b1..106181ef224240ca942a722d8a985e8684bd75db 100644
--- a/contrib/pgcrypto/expected/rijndael.out
+++ b/contrib/pgcrypto/expected/rijndael.out
@@ -1,6 +1,8 @@
 --
 -- AES / Rijndael-128 cipher
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 -- some standard Rijndael testvalues
 SELECT encode(encrypt(
 decode('00112233445566778899aabbccddeeff', 'hex'),
diff --git a/contrib/pgcrypto/sql/blowfish.sql b/contrib/pgcrypto/sql/blowfish.sql
index c0383f54218044b1c6f8fffc457b2b00704640e3..1a8536d686b7ed4dd5a6b96c2848d4cf3d5b5bc9 100644
--- a/contrib/pgcrypto/sql/blowfish.sql
+++ b/contrib/pgcrypto/sql/blowfish.sql
@@ -1,6 +1,8 @@
 --
 -- Blowfish cipher
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 
 -- some standard Blowfish testvalues
 SELECT encode(encrypt(
diff --git a/contrib/pgcrypto/sql/init.sql b/contrib/pgcrypto/sql/init.sql
index a58b3f0144dc2ee23a5fc9890ad5b590701e4103..ee1c231bdc2c5b34a9992e64b4e4d7c9c88e1d94 100644
--- a/contrib/pgcrypto/sql/init.sql
+++ b/contrib/pgcrypto/sql/init.sql
@@ -12,6 +12,9 @@ SET client_min_messages = warning;
 \set ECHO all
 RESET client_min_messages;
 
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
+
 -- check for encoding fn's
 SELECT encode('foo', 'hex');
 SELECT decode('666f6f', 'hex');
diff --git a/contrib/pgcrypto/sql/pgp-armor.sql b/contrib/pgcrypto/sql/pgp-armor.sql
index 040c4ac038fae436e88d07ba9c1173b744be83ff..71ffba26a0afc57fd30ef0496fce3d6390ebd5e3 100644
--- a/contrib/pgcrypto/sql/pgp-armor.sql
+++ b/contrib/pgcrypto/sql/pgp-armor.sql
@@ -1,6 +1,8 @@
 --
 -- PGP Armor
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 
 select armor('');
 select armor('test');
diff --git a/contrib/pgcrypto/sql/pgp-encrypt.sql b/contrib/pgcrypto/sql/pgp-encrypt.sql
index 03b34c8ad2527826954be994f6e45ce8c8f2caf7..218bd419e5e03e3fb09302cce3dc06c2a89a0f7b 100644
--- a/contrib/pgcrypto/sql/pgp-encrypt.sql
+++ b/contrib/pgcrypto/sql/pgp-encrypt.sql
@@ -1,6 +1,8 @@
 --
 -- PGP encrypt
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 
 select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'), 'key');
 
diff --git a/contrib/pgcrypto/sql/pgp-pubkey-encrypt.sql b/contrib/pgcrypto/sql/pgp-pubkey-encrypt.sql
index 62dd487c10ff70afa52a2bc5072911be058e402b..2c4e622e5c8ef1853a8c2b7423e2a6dc212682e9 100644
--- a/contrib/pgcrypto/sql/pgp-pubkey-encrypt.sql
+++ b/contrib/pgcrypto/sql/pgp-pubkey-encrypt.sql
@@ -1,6 +1,8 @@
 --
 -- PGP Public Key Encryption
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 
 -- successful encrypt/decrypt
 select pgp_pub_decrypt(
diff --git a/contrib/pgcrypto/sql/rijndael.sql b/contrib/pgcrypto/sql/rijndael.sql
index 4d6af0ffaa22a6247f2fe9e400e87f7a0dcc2b7e..428ad1332c2fc7cf684c33198c2884da1c0f1de6 100644
--- a/contrib/pgcrypto/sql/rijndael.sql
+++ b/contrib/pgcrypto/sql/rijndael.sql
@@ -1,6 +1,8 @@
 --
 -- AES / Rijndael-128 cipher
 --
+-- ensure consistent test output regardless of the default bytea format
+SET bytea_output TO escape;
 
 -- some standard Rijndael testvalues
 SELECT encode(encrypt(