From 6206a880cf233e5bf70a0ced6be810c399c7e006 Mon Sep 17 00:00:00 2001
From: Tatsuo Ishii <ishii@postgresql.org>
Date: Tue, 6 Aug 2002 05:40:47 +0000
Subject: [PATCH] Add SQL99 CONVERT() function.

---
 doc/src/sgml/func.sgml                        | 414 +++++++++++++-
 src/backend/catalog/namespace.c               |  39 +-
 src/backend/catalog/pg_conversion.c           | 133 +++--
 src/backend/parser/gram.y                     |  61 ++-
 src/backend/parser/keywords.c                 |   3 +-
 src/backend/utils/mb/Makefile                 |   4 +-
 .../utils/mb/conversion_procs/Makefile        |  32 +-
 .../mb/conversion_procs/regress_epilogue      |   5 +
 .../utils/mb/conversion_procs/regress_prolog  |  25 +
 src/include/catalog/catversion.h              |   4 +-
 src/include/catalog/namespace.h               |   3 +-
 src/include/catalog/pg_conversion.h           |   8 +-
 src/include/catalog/pg_proc.h                 |   5 +-
 src/test/regress/expected/conversion.out      | 516 +++++++++++++++---
 src/test/regress/sql/conversion.sql           | 196 ++++---
 15 files changed, 1237 insertions(+), 211 deletions(-)
 create mode 100644 src/backend/utils/mb/conversion_procs/regress_epilogue
 create mode 100644 src/backend/utils/mb/conversion_procs/regress_prolog

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index dfebb45e1bc..aed47db79b9 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.107 2002/08/04 19:51:30 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.108 2002/08/06 05:40:44 ishii Exp $
 PostgreSQL documentation
 -->
 
@@ -857,6 +857,19 @@ PostgreSQL documentation
        <entry><literal>4</literal></entry>
       </row>
 
+      <row>
+       <entry><function>convert</function>(<parameter>string</parameter>
+       using <parameter>conversion_name</parameter>)</entry>
+       <entry><type>text</type></entry>
+       <entry>Change encoding using specified conversion name.
+       Conversions can be defined by <command>CREATE CONVERSION</command>.
+       Also there are some pre-defined conversion names. 
+       See <xref linkend="conversion-names"> for available
+       conversion names. </entry>
+       <entry><literal>convert('PostgreSQL' using iso8859_1_to_utf8)</literal></entry>
+       <entry><literal>'PostgreSQL' in UNICODE(UTF-8) encoding</literal></entry>
+      </row>
+
       <row>
        <entry><function>lower</function>(<parameter>string</parameter>)</entry>
        <entry><type>text</type></entry>
@@ -947,6 +960,405 @@ PostgreSQL documentation
     </tgroup>
    </table>
 
+   <table id="conversion-names">
+    <title>Available conversion names</title>
+    <tgroup cols="3">
+     <thead>
+      <row>
+       <entry>conversion</entry>
+       <entry>source encoding</entry>
+       <entry>destination encoding</entry>
+      </row>
+     </thead>
+     <tbody>
+      <row>
+       <entry>ascii_to_utf8</entry>
+       <entry>SQL_ASCII</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>big5_to_euc_tw</entry>
+       <entry>BIG5</entry>
+       <entry>EUC_TW</entry>
+      </row>
+
+      <row>
+       <entry>big5_to_mic</entry>
+       <entry>BIG5</entry>
+       <entry>MULE_INTERNAL</entry>
+      </row>
+
+      <row>
+       <entry>big5_to_utf8</entry>
+       <entry>BIG5</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>euc_cn_to_utf8</entry>
+       <entry>EUC_CN</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>euc_jp_to_mic</entry>
+       <entry>EUC_JP</entry>
+       <entry>MULE_INTERNAL</entry>
+      </row>
+
+      <row>
+       <entry>euc_jp_to_sjis</entry>
+       <entry>EUC_JP</entry>
+       <entry>SJIS</entry>
+      </row>
+
+      <row>
+       <entry>euc_jp_to_utf8</entry>
+       <entry>EUC_JP</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>euc_kr_to_utf8</entry>
+       <entry>EUC_KR</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>euc_tw_to_big5</entry>
+       <entry>EUC_TW</entry>
+       <entry>BIG5</entry>
+      </row>
+
+      <row>
+       <entry>euc_tw_to_mic</entry>
+       <entry>EUC_TW</entry>
+       <entry>MULE_INTERNAL</entry>
+      </row>
+
+      <row>
+       <entry>euc_tw_to_utf8</entry>
+       <entry>EUC_TW</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>gb18030_to_utf8</entry>
+       <entry>GB18030</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>gbk_to_utf8</entry>
+       <entry>GBK</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_10_to_utf8</entry>
+       <entry>LATIN6</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_13_to_utf8</entry>
+       <entry>LATIN7</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_14_to_utf8</entry>
+       <entry>LATIN8</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_15_to_utf8</entry>
+       <entry>LATIN9</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_16_to_utf8</entry>
+       <entry>LATIN10</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_1_to_utf8</entry>
+       <entry>LATIN1</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_2_to_utf8</entry>
+       <entry>LATIN2</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_3_to_utf8</entry>
+       <entry>LATIN3</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_4_to_utf8</entry>
+       <entry>LATIN4</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_5_to_utf8</entry>
+       <entry>ISO_8859_5</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_6_to_utf8</entry>
+       <entry>ISO_8859_6</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_7_to_utf8</entry>
+       <entry>ISO_8859_7</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_8_to_utf8</entry>
+       <entry>ISO_8859_8</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>iso8859_9_to_utf8</entry>
+       <entry>LATIN5</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>johab_to_utf8</entry>
+       <entry>JOHAB</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>mic_to_big5</entry>
+       <entry>MULE_INTERNAL</entry>
+       <entry>BIG5</entry>
+      </row>
+
+      <row>
+       <entry>mic_to_euc_jp</entry>
+       <entry>MULE_INTERNAL</entry>
+       <entry>EUC_JP</entry>
+      </row>
+
+      <row>
+       <entry>mic_to_euc_tw</entry>
+       <entry>MULE_INTERNAL</entry>
+       <entry>EUC_TW</entry>
+      </row>
+
+      <row>
+       <entry>mic_to_sjis</entry>
+       <entry>MULE_INTERNAL</entry>
+       <entry>SJIS</entry>
+      </row>
+
+      <row>
+       <entry>sjis_to_euc_jp</entry>
+       <entry>SJIS</entry>
+       <entry>EUC_JP</entry>
+      </row>
+
+      <row>
+       <entry>sjis_to_mic</entry>
+       <entry>SJIS</entry>
+       <entry>MULE_INTERNAL</entry>
+      </row>
+
+      <row>
+       <entry>sjis_to_utf8</entry>
+       <entry>SJIS</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>tcvn_to_utf8</entry>
+       <entry>TCVN</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>uhc_to_utf8</entry>
+       <entry>UHC</entry>
+       <entry>UNICODE</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_ascii</entry>
+       <entry>UNICODE</entry>
+       <entry>SQL_ASCII</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_big5</entry>
+       <entry>UNICODE</entry>
+       <entry>BIG5</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_euc_cn</entry>
+       <entry>UNICODE</entry>
+       <entry>EUC_CN</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_euc_jp</entry>
+       <entry>UNICODE</entry>
+       <entry>EUC_JP</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_euc_kr</entry>
+       <entry>UNICODE</entry>
+       <entry>EUC_KR</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_euc_tw</entry>
+       <entry>UNICODE</entry>
+       <entry>EUC_TW</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_gb18030</entry>
+       <entry>UNICODE</entry>
+       <entry>GB18030</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_gbk</entry>
+       <entry>UNICODE</entry>
+       <entry>GBK</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_1</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN1</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_10</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN6</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_13</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN7</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_14</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN8</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_15</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN9</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_16</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN10</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_2</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN2</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_3</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN3</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_4</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN4</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_5</entry>
+       <entry>UNICODE</entry>
+       <entry>ISO_8859_5</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_6</entry>
+       <entry>UNICODE</entry>
+       <entry>ISO_8859_6</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_7</entry>
+       <entry>UNICODE</entry>
+       <entry>ISO_8859_7</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_8</entry>
+       <entry>UNICODE</entry>
+       <entry>ISO_8859_8</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_iso8859_9</entry>
+       <entry>UNICODE</entry>
+       <entry>LATIN5</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_johab</entry>
+       <entry>UNICODE</entry>
+       <entry>JOHAB</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_sjis</entry>
+       <entry>UNICODE</entry>
+       <entry>SJIS</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_tcvn</entry>
+       <entry>UNICODE</entry>
+       <entry>TCVN</entry>
+      </row>
+
+      <row>
+       <entry>utf8_to_uhc</entry>
+       <entry>UNICODE</entry>
+       <entry>UHC</entry>
+      </row>
+
+     </tbody>
+    </tgroup>
+   </table>
+
    <para>
     Additional string manipulation functions are available and are
     listed below.  Some of them are used internally to implement the
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 0425e44c1cd..bc2098034f3 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.27 2002/07/29 23:46:35 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.28 2002/08/06 05:40:44 ishii Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1238,6 +1238,43 @@ PopSpecialNamespace(Oid namespaceId)
 	namespaceSearchPathValid = false;
 }
 
+/*
+ * FindConversionByName - find a conversion by possibly qualified name
+ */
+Oid FindConversionByName(List *name)
+{
+	char		*conversion_name;
+	Oid	namespaceId;
+	Oid conoid;
+	List	   *lptr;
+
+	/* Convert list of names to a name and namespace */
+	namespaceId = QualifiedNameGetCreationNamespace(name, &conversion_name);
+
+	if (length(name) > 1)
+	{
+		/* Check we have usage rights in target namespace */
+		if (pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE) != ACLCHECK_OK)
+			return InvalidOid;
+
+		return FindConversion(conversion_name, namespaceId);
+	}
+
+	recomputeNamespacePath();
+
+	foreach(lptr, namespaceSearchPath)
+	{
+		Oid			namespaceId = (Oid) lfirsti(lptr);
+
+		conoid = FindConversion(conversion_name, namespaceId);
+		if (OidIsValid(conoid))
+			return conoid;
+	}
+
+	/* Not found in path */
+	return InvalidOid;
+}
+
 /*
  * FindDefaultConversionProc - find default encoding cnnversion proc
  */
diff --git a/src/backend/catalog/pg_conversion.c b/src/backend/catalog/pg_conversion.c
index c422e33e317..7dfd0679a22 100644
--- a/src/backend/catalog/pg_conversion.c
+++ b/src/backend/catalog/pg_conversion.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.4 2002/08/05 03:29:16 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.5 2002/08/06 05:40:45 ishii Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -221,7 +221,7 @@ RemoveConversionById(Oid conversionOid)
 	if (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection)))
 		simple_heap_delete(rel, &tuple->t_self);
 	else
-		elog(ERROR, "Conversion %u does not exist", conversionOid);
+		elog(ERROR, "conversion %u does not exist", conversionOid);
 	heap_endscan(scan);
 	heap_close(rel, RowExclusiveLock);
 }
@@ -233,47 +233,6 @@ RemoveConversionById(Oid conversionOid)
  * If found, returns the procedure's oid, otherwise InvalidOid.
  * ---------------
  */
-#ifdef NOT_USED
-Oid FindDefaultConversion(Oid name_space, int4 for_encoding, int4 to_encoding)
-{
-	Relation rel;
-	HeapScanDesc scan;
-	ScanKeyData scanKeyData;
-	HeapTuple	tuple;
-	Form_pg_conversion body;
-	Oid proc = InvalidOid;
-
-	/* Check we have usage rights in target namespace */
-	if (pg_namespace_aclcheck(name_space, GetUserId(), ACL_USAGE) != ACLCHECK_OK)
-		return InvalidOid;
-
-	ScanKeyEntryInitialize(&scanKeyData,
-						   0,
-						   Anum_pg_conversion_connamespace,
-						   F_OIDEQ,
-						   ObjectIdGetDatum(name_space));
-
-	rel = heap_openr(ConversionRelationName, AccessShareLock);
-	scan = heap_beginscan(rel, SnapshotNow,
-							  1, &scanKeyData);
-
-	while (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection)))
-	{
-		body = (Form_pg_conversion)GETSTRUCT(tuple);
-		if (body->conforencoding == for_encoding &&
-			body->contoencoding == to_encoding &&
-			body->condefault == TRUE)
-		{
-			proc = body->conproc;
-			break;
-		}
-	}
-	heap_endscan(scan);
-	heap_close(rel, AccessShareLock);
-	return proc;
-}
-#endif
-
 Oid FindDefaultConversion(Oid name_space, int4 for_encoding, int4 to_encoding)
 {
 	CatCList	*catlist;
@@ -309,34 +268,27 @@ Oid FindDefaultConversion(Oid name_space, int4 for_encoding, int4 to_encoding)
 /* ----------------
  * FindConversionByName
  *
- * Find conversion proc by possibly qualified conversion name.
+ * Find conversion by namespace and conversion name.
+ * Returns conversion oid.
  * ---------------
  */
-Oid FindConversionByName(List *name)
+Oid FindConversion(const char *conname, Oid connamespace)
 {
 	HeapTuple	tuple;
-	char		*conversion_name;
-	Oid	namespaceId;
 	Oid procoid;
+	Oid conoid;
 	AclResult	aclresult;
 
-	/* Convert list of names to a name and namespace */
-	namespaceId = QualifiedNameGetCreationNamespace(name, &conversion_name);
-
-	/* Check we have usage rights in target namespace */
-	if (pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE) != ACLCHECK_OK)
-		return InvalidOid;
-
-	/* search pg_conversion by namespaceId and conversion name */
+	/* search pg_conversion by connamespace and conversion name */
 	tuple = SearchSysCache(CONNAMESP,
-						   PointerGetDatum(conversion_name),
-						   ObjectIdGetDatum(namespaceId),
+						   PointerGetDatum(conname),
+						   ObjectIdGetDatum(connamespace),
 						   0,0);
 
 	if (!HeapTupleIsValid(tuple))
 		return InvalidOid;
-
 	procoid = ((Form_pg_conversion)GETSTRUCT(tuple))->conproc;
+	conoid = HeapTupleGetOid(tuple);
 
 	ReleaseSysCache(tuple);
 
@@ -345,6 +297,69 @@ Oid FindConversionByName(List *name)
 	if (aclresult != ACLCHECK_OK)
 		return InvalidOid;
 
-	return procoid;
+	return conoid;
 }
 
+/*
+ * Execute SQL99's CONVERT function.
+ *
+ * CONVERT <left paren> <character value expression>
+ * USING <form-of-use conversion name> <right paren>
+ *
+ * TEXT convert3(TEXT string, OID conversion_oid);
+ */
+Datum
+pg_convert3(PG_FUNCTION_ARGS)
+{
+	text	   *string = PG_GETARG_TEXT_P(0);
+	Oid			convoid = PG_GETARG_OID(1);
+	HeapTuple	tuple;
+	Form_pg_conversion body;
+	text	   *retval;
+	unsigned char *str;
+	unsigned char *result;
+	int len;
+
+	if (!OidIsValid(convoid))
+		elog(ERROR, "Conversion does not exist");
+
+	/* make sure that source string is null terminated */
+	len = VARSIZE(string) - VARHDRSZ;
+	str = palloc(len + 1);
+	memcpy(str, VARDATA(string), len);
+	*(str + len) = '\0';
+
+	tuple = SearchSysCache(CONOID,
+						   ObjectIdGetDatum(convoid),
+						   0,0,0);
+	if (!HeapTupleIsValid(tuple))
+		elog(ERROR, "Conversion %u search from syscache failed", convoid);
+
+	result = palloc(len * 4 + 1);
+
+	body = (Form_pg_conversion)GETSTRUCT(tuple);
+	OidFunctionCall5(body->conproc,
+					 Int32GetDatum(body->conforencoding),
+					 Int32GetDatum(body->contoencoding),
+					 CStringGetDatum(str),
+					 CStringGetDatum(result),
+					 Int32GetDatum(len));
+
+	ReleaseSysCache(tuple);
+
+	/* build text data type structre. we cannot use textin() here,
+	   since textin assumes that input string encoding is same as
+	   database encoding.  */
+	len = strlen(result) + VARHDRSZ;
+	retval = palloc(len);
+	VARATT_SIZEP(retval) = len;
+	memcpy(VARDATA(retval), result, len - VARHDRSZ);
+
+	pfree(result);
+	pfree(str);
+
+	/* free memory if allocated by the toaster */
+	PG_FREE_IF_COPY(string, 0);
+
+	PG_RETURN_TEXT_P(retval);
+}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 5c77aebfe62..f57f461124d 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.356 2002/08/05 02:30:50 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.357 2002/08/06 05:40:45 ishii Exp $
  *
  * HISTORY
  *	  AUTHOR			DATE			MAJOR EVENT
@@ -53,6 +53,7 @@
 #include "access/htup.h"
 #include "catalog/index.h"
 #include "catalog/namespace.h"
+#include "catalog/pg_conversion.h"
 #include "catalog/pg_type.h"
 #include "nodes/makefuncs.h"
 #include "nodes/params.h"
@@ -216,7 +217,8 @@ static void doNegateFloat(Value *v);
 				insert_target_list, def_list, opt_indirection,
 				group_clause, TriggerFuncArgs, select_limit,
 				opt_select_limit, opclass_item_list, trans_options,
-				TableFuncElementList, OptTableFuncElementList
+				TableFuncElementList, OptTableFuncElementList,
+				convert_args
 
 %type <range>	into_clause, OptTempTableName
 
@@ -232,7 +234,7 @@ static void doNegateFloat(Value *v);
 %type <jtype>	join_type
 
 %type <list>	extract_list, overlay_list, position_list
-%type <list>	substr_list, trim_list
+%type <list>	substr_list, trim_list, convert_list
 %type <ival>	opt_interval
 %type <node>	overlay_placing, substr_from, substr_for
 
@@ -329,7 +331,7 @@ static void doNegateFloat(Value *v);
 	CACHE, CALLED, CASCADE, CASE, CAST, CHAIN, CHAR_P,
 	CHARACTER, CHARACTERISTICS, CHECK, CHECKPOINT, CLASS, CLOSE,
 	CLUSTER, COALESCE, COLLATE, COLUMN, COMMENT, COMMIT,
-	COMMITTED, CONSTRAINT, CONSTRAINTS, CONVERSION_P, COPY, CREATE, CREATEDB,
+	COMMITTED, CONSTRAINT, CONSTRAINTS, CONVERSION_P, CONVERT, COPY, CREATE, CREATEDB,
 	CREATEUSER, CROSS, CURRENT_DATE, CURRENT_TIME,
 	CURRENT_TIMESTAMP, CURRENT_USER, CURSOR, CYCLE,
 
@@ -6253,6 +6255,15 @@ c_expr:		columnref								{ $$ = (Node *) $1; }
 					n->agg_distinct = FALSE;
 					$$ = (Node *)n;
 				}
+			| CONVERT '(' convert_list ')'
+				{
+					FuncCall *n = makeNode(FuncCall);
+					n->funcname = SystemFuncName("convert");
+					n->args = $3;
+					n->agg_star = FALSE;
+					n->agg_distinct = FALSE;
+					$$ = (Node *)n;
+				}
 			| select_with_parens			%prec UMINUS
 				{
 					SubLink *n = makeNode(SubLink);
@@ -6418,6 +6429,48 @@ trim_list:	a_expr FROM expr_list					{ $$ = lappend($3, $1); }
 			| expr_list								{ $$ = $1; }
 		;
 
+/* CONVERT() arguments. We accept followings:
+ * SQL99 syntax
+ * o CONVERT(TEXT string USING conversion_name)
+ *
+ * Function calls
+ * o CONVERT(TEXT string, NAME src_encoding_name, NAME dest_encoding_name)
+ * o CONVERT(TEXT string, NAME encoding_name)
+ */
+convert_list:
+			a_expr USING any_name
+				{
+					Oid oid = FindConversionByName($3);
+					Const *convoid = makeNode(Const);
+
+					if (!OidIsValid(oid))
+					{
+					    elog(ERROR, "Conversion \"%s\" does not exist",
+						 NameListToString($3));
+					}
+
+					convoid->consttype = OIDOID;
+					convoid->constlen = sizeof(Oid);
+					convoid->constvalue = oid;
+					convoid->constisnull = FALSE;
+					convoid->constbyval = TRUE;
+					convoid->constisset = FALSE;
+					convoid->constiscast = FALSE;
+					$$ = makeList2($1, convoid);
+				}
+			| convert_args
+				{
+				  $$ = $1;
+				}
+			| /*EMPTY*/
+				{ $$ = NIL; }
+		;
+
+convert_args:	a_expr								{ $$ = makeList1($1); }
+			| convert_args ',' a_expr					{ $$ = lappend($1, $3); }
+  		;
+  
+
 in_expr:	select_with_parens
 				{
 					SubLink *n = makeNode(SubLink);
diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c
index 32733d8f546..2ae62ac18d9 100644
--- a/src/backend/parser/keywords.c
+++ b/src/backend/parser/keywords.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.123 2002/07/29 22:14:11 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.124 2002/08/06 05:40:45 ishii Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -80,6 +80,7 @@ static const ScanKeyword ScanKeywords[] = {
 	{"constraint", CONSTRAINT},
 	{"constraints", CONSTRAINTS},
 	{"conversion", CONVERSION_P},
+	{"convert", CONVERT},
 	{"copy", COPY},
 	{"create", CREATE},
 	{"createdb", CREATEDB},
diff --git a/src/backend/utils/mb/Makefile b/src/backend/utils/mb/Makefile
index 64b60a510a4..ea460aa5297 100644
--- a/src/backend/utils/mb/Makefile
+++ b/src/backend/utils/mb/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for utils/mb
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.18 2002/07/18 02:02:30 ishii Exp $
+#    $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.19 2002/08/06 05:40:45 ishii Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -24,7 +24,7 @@ clean distclean maintainer-clean:
 
 SUBSYS.o: $(OBJS)
 	@for dir in $(DIRS); do $(MAKE) -C $$dir all || exit; done
-	$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
+	$(LD) $(LDREL) $(LDOUT) $@ $^
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
diff --git a/src/backend/utils/mb/conversion_procs/Makefile b/src/backend/utils/mb/conversion_procs/Makefile
index 30ff1384080..a1ab66bc282 100644
--- a/src/backend/utils/mb/conversion_procs/Makefile
+++ b/src/backend/utils/mb/conversion_procs/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for utils/mb/conversion_procs
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/Makefile,v 1.2 2002/07/18 22:58:08 petere Exp $
+#    $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/Makefile,v 1.3 2002/08/06 05:40:45 ishii Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -14,6 +14,9 @@ include $(top_builddir)/src/Makefile.global
 
 SQLSCRIPT = conversion_create.sql
 
+# This file can be placed as src/test/regress/conversion.sql
+REGRESSION_SCRIPT = conversion.sql
+
 DIRS = \
 	utf8_and_ascii utf8_and_iso8859_1 \
 	utf8_and_euc_jp utf8_and_euc_kr utf8_and_euc_cn utf8_and_euc_tw \
@@ -21,9 +24,7 @@ DIRS = \
 	utf8_and_uhc utf8_and_johab utf8_and_tcvn utf8_and_iso8859 \
 	euc_jp_and_sjis euc_tw_and_big5
 
-# conversion_name source_encoding destination_encoding function object
-$(SQLSCRIPT): Makefile
-	@set \
+CONVERSIONS = \
 		utf8_to_ascii UNICODE SQL_ASCII utf8_to_ascii utf8_and_ascii \
 		ascii_to_utf8 SQL_ASCII UNICODE ascii_to_utf8 utf8_and_ascii \
 		utf8_to_iso8859_1 UNICODE LATIN1 utf8_to_iso8859_1 utf8_and_iso8859_1 \
@@ -87,8 +88,11 @@ $(SQLSCRIPT): Makefile
 		euc_tw_to_mic	EUC_TW MULE_INTERNAL euc_tw_to_mic euc_tw_and_big5 \
 		big5_to_mic	BIG5 MULE_INTERNAL big5_to_mic euc_tw_and_big5 \
 		mic_to_euc_tw	MULE_INTERNAL EUC_TW mic_to_euc_tw euc_tw_and_big5 \
-		mic_to_big5	MULE_INTERNAL BIG5 mic_to_big5 euc_tw_and_big5 \
-	; \
+		mic_to_big5	MULE_INTERNAL BIG5 mic_to_big5 euc_tw_and_big5
+
+# conversion_name source_encoding destination_encoding function object
+$(SQLSCRIPT): Makefile
+	@set $(CONVERSIONS) ; \
 	while [ "$$#" -gt 0 ] ; \
 	do \
 		name=$$1;shift; \
@@ -102,6 +106,22 @@ $(SQLSCRIPT): Makefile
 		echo "CREATE DEFAULT CONVERSION pg_catalog.$$name FOR '$$se' TO '$$de' FROM $$func;"; \
 	done > $@
 
+$(REGRESSION_SCRIPT): Makefile
+	@cp regress_prolog $@; \
+	set $(CONVERSIONS) ; \
+	while [ "$$#" -gt 0 ] ; \
+	do \
+		name=$$1;shift; \
+		se=$$1;shift; \
+		de=$$1; shift; \
+		func=$$1; shift; \
+		obj=$$1; shift; \
+		echo "-- $$se --> $$de"; \
+		echo "SELECT CONVERT('foo' USING $$name);"; \
+		echo "SELECT CONVERT('foo', '$$se', '$$de');"; \
+	done >> $@; \
+	cat regress_epilogue >> $@;
+
 install: all installdirs
 	$(INSTALL_DATA) $(SQLSCRIPT) $(DESTDIR)$(datadir)
 	@for dir in $(DIRS); do $(MAKE) -C $$dir $@ || exit; done
diff --git a/src/backend/utils/mb/conversion_procs/regress_epilogue b/src/backend/utils/mb/conversion_procs/regress_epilogue
new file mode 100644
index 00000000000..da8238b9f39
--- /dev/null
+++ b/src/backend/utils/mb/conversion_procs/regress_epilogue
@@ -0,0 +1,5 @@
+--
+-- return to the super user
+--
+RESET SESSION AUTHORIZATION;
+DROP USER foo;
diff --git a/src/backend/utils/mb/conversion_procs/regress_prolog b/src/backend/utils/mb/conversion_procs/regress_prolog
new file mode 100644
index 00000000000..62a90d20b63
--- /dev/null
+++ b/src/backend/utils/mb/conversion_procs/regress_prolog
@@ -0,0 +1,25 @@
+--
+-- create user defined conversion
+--
+CREATE USER foo WITH NOCREATEDB NOCREATEUSER;
+SET SESSION AUTHORIZATION foo;
+CREATE CONVERSION myconv FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8;
+--
+-- cannot make same name conversion in same schema
+--
+CREATE CONVERSION myconv FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8;
+--
+-- create default conversion with qualified name
+--
+CREATE DEFAULT CONVERSION public.mydef FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8;
+--
+-- cannot make default conversion with same shcema/for_encoding/to_encoding
+--
+CREATE DEFAULT CONVERSION public.mydef2 FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8;
+--
+-- drop user defined conversion
+--
+DROP CONVERSION myconv;
+DROP CONVERSION mydef;
+--
+-- make sure all pre-defined conversions are fine.
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 12669ed78dd..f3dfa81879d 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catversion.h,v 1.145 2002/08/04 19:48:10 momjian Exp $
+ * $Id: catversion.h,v 1.146 2002/08/06 05:40:45 ishii Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*							yyyymmddN */
-#define CATALOG_VERSION_NO	200208041
+#define CATALOG_VERSION_NO	200208061
 
 #endif
diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h
index bd0f176f28a..f7e4ec32fdf 100644
--- a/src/include/catalog/namespace.h
+++ b/src/include/catalog/namespace.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: namespace.h,v 1.17 2002/07/29 23:46:35 tgl Exp $
+ * $Id: namespace.h,v 1.18 2002/08/06 05:40:45 ishii Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -80,6 +80,7 @@ extern bool isTempNamespace(Oid namespaceId);
 extern void PushSpecialNamespace(Oid namespaceId);
 extern void PopSpecialNamespace(Oid namespaceId);
 
+extern Oid FindConversionByName(List *conname);
 extern Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding);
 
 /* initialization & transaction cleanup code */
diff --git a/src/include/catalog/pg_conversion.h b/src/include/catalog/pg_conversion.h
index de08137bff8..e250d6d5d0a 100644
--- a/src/include/catalog/pg_conversion.h
+++ b/src/include/catalog/pg_conversion.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_conversion.h,v 1.3 2002/08/04 06:54:10 thomas Exp $
+ * $Id: pg_conversion.h,v 1.4 2002/08/06 05:40:45 ishii Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -90,7 +90,9 @@ extern Oid	ConversionCreate(const char *conname, Oid connamespace,
 extern void ConversionDrop(const char *conname, Oid connamespace,
 						   int32 conowner, DropBehavior behavior);
 extern void RemoveConversionById(Oid conversionOid);
-extern Oid FindDefaultConversion(Oid name_space, int4 for_encoding, int4 to_encoding);
-extern Oid FindConversionByName(List *conname);
+extern Oid FindConversion(const char *conname, Oid connamespace);
+extern Oid FindDefaultConversion(Oid connamespace, int4 for_encoding, int4 to_encoding);
+
+extern Datum pg_convert3(PG_FUNCTION_ARGS);
 
 #endif   /* PG_CONVERSION_H */
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 3520af4cecf..afd8a782cc2 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_proc.h,v 1.251 2002/08/04 23:46:38 tgl Exp $
+ * $Id: pg_proc.h,v 1.252 2002/08/06 05:40:45 ishii Exp $
  *
  * NOTES
  *	  The script catalog/genbki.sh reads this file and generates .bki
@@ -2149,6 +2149,9 @@ DESCR("convert string with specified destination encoding name");
 DATA(insert OID = 1813 (  convert		   PGNSP PGUID 12 f f t f s 3 25 "25 19 19"  pg_convert2 - _null_ ));
 DESCR("convert string with specified encoding names");
 
+DATA(insert OID = 90 (  convert		   PGNSP PGUID 12 f f t f s 2 25 "25 26"  pg_convert3 - _null_ ));
+DESCR("convert string with specified conversion oid");
+
 DATA(insert OID = 1264 (  pg_char_to_encoding	   PGNSP PGUID 12 f f t f s 1 23 "19"  PG_char_to_encoding - _null_ ));
 DESCR("convert encoding name to encoding id");
 
diff --git a/src/test/regress/expected/conversion.out b/src/test/regress/expected/conversion.out
index d1b3cdfba87..f1f496464b1 100644
--- a/src/test/regress/expected/conversion.out
+++ b/src/test/regress/expected/conversion.out
@@ -25,454 +25,840 @@ DROP CONVERSION myconv;
 DROP CONVERSION mydef;
 --
 -- make sure all pre-defined conversions are fine.
---
--- UNICODE -> SQL_ASCII
+-- UNICODE --> SQL_ASCII
+SELECT CONVERT('foo' USING utf8_to_ascii);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'SQL_ASCII');
  convert 
 ---------
  foo
 (1 row)
 
--- SQL_ASCII -> UNICODE
+-- SQL_ASCII --> UNICODE
+SELECT CONVERT('foo' USING ascii_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'SQL_ASCII', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN1
+-- UNICODE --> LATIN1
+SELECT CONVERT('foo' USING utf8_to_iso8859_1);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN1');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN1 -> UNICODE
+-- LATIN1 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_1_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN1', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_JP -> UNICODE
+-- EUC_JP --> UNICODE
+SELECT CONVERT('foo' USING euc_jp_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_JP', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> EUC_JP
+-- UNICODE --> EUC_JP
+SELECT CONVERT('foo' USING utf8_to_euc_jp);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'EUC_JP');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_KR -> UNICODE
+-- EUC_KR --> UNICODE
+SELECT CONVERT('foo' USING euc_kr_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_KR', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> EUC_KR
+-- UNICODE --> EUC_KR
+SELECT CONVERT('foo' USING utf8_to_euc_kr);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'EUC_KR');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_CN -> UNICODE
+-- EUC_CN --> UNICODE
+SELECT CONVERT('foo' USING euc_cn_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_CN', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> EUC_CN
+-- UNICODE --> EUC_CN
+SELECT CONVERT('foo' USING utf8_to_euc_cn);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'EUC_CN');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_TW -> UNICODE
+-- EUC_TW --> UNICODE
+SELECT CONVERT('foo' USING euc_tw_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_TW', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> EUC_TW
+-- UNICODE --> EUC_TW
+SELECT CONVERT('foo' USING utf8_to_euc_tw);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'EUC_TW');
  convert 
 ---------
  foo
 (1 row)
 
--- SJIS -> UNICODE
+-- SJIS --> UNICODE
+SELECT CONVERT('foo' USING sjis_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'SJIS', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> SJIS
+-- UNICODE --> SJIS
+SELECT CONVERT('foo' USING utf8_to_sjis);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'SJIS');
  convert 
 ---------
  foo
 (1 row)
 
--- BIG5 -> UNICODE
+-- BIG5 --> UNICODE
+SELECT CONVERT('foo' USING big5_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'BIG5', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> BIG5
+-- UNICODE --> BIG5
+SELECT CONVERT('foo' USING utf8_to_big5);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'BIG5');
  convert 
 ---------
  foo
 (1 row)
 
--- GBK -> UNICODE
+-- GBK --> UNICODE
+SELECT CONVERT('foo' USING gbk_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'GBK', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> GBK
+-- UNICODE --> GBK
+SELECT CONVERT('foo' USING utf8_to_gbk);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'GBK');
  convert 
 ---------
  foo
 (1 row)
 
--- GB18030 -> UNICODE
+-- GB18030 --> UNICODE
+SELECT CONVERT('foo' USING gb18030_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'GB18030', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> GB18030
+-- UNICODE --> GB18030
+SELECT CONVERT('foo' USING utf8_to_gb18030);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'GB18030');
  convert 
 ---------
  foo
 (1 row)
 
--- UHC -> UNICODE
+-- UHC --> UNICODE
+SELECT CONVERT('foo' USING uhc_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UHC', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> UHC
+-- UNICODE --> UHC
+SELECT CONVERT('foo' USING utf8_to_uhc);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'UHC');
  convert 
 ---------
  foo
 (1 row)
 
--- JOHAB -> UNICODE
+-- JOHAB --> UNICODE
+SELECT CONVERT('foo' USING johab_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'JOHAB', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> JOHAB
+-- UNICODE --> JOHAB
+SELECT CONVERT('foo' USING utf8_to_johab);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'JOHAB');
  convert 
 ---------
  foo
 (1 row)
 
--- TCVN -> UNICODE
+-- TCVN --> UNICODE
+SELECT CONVERT('foo' USING tcvn_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'TCVN', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> TCVN
+-- UNICODE --> TCVN
+SELECT CONVERT('foo' USING utf8_to_tcvn);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'TCVN');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN2
+-- UNICODE --> LATIN2
+SELECT CONVERT('foo' USING utf8_to_iso8859_2);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN2');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN2 -> UNICODE
+-- LATIN2 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_2_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN2', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN3
+-- UNICODE --> LATIN3
+SELECT CONVERT('foo' USING utf8_to_iso8859_3);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN3');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN3 -> UNICODE
+-- LATIN3 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_3_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN3', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN4
+-- UNICODE --> LATIN4
+SELECT CONVERT('foo' USING utf8_to_iso8859_4);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN4');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN4 -> UNICODE
+-- LATIN4 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_4_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN4', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN5
+-- UNICODE --> LATIN5
+SELECT CONVERT('foo' USING utf8_to_iso8859_9);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN5');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN5 -> UNICODE
+-- LATIN5 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_9_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN5', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN6
+-- UNICODE --> LATIN6
+SELECT CONVERT('foo' USING utf8_to_iso8859_10);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN6');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN6 -> UNICODE
+-- LATIN6 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_10_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN6', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN7
+-- UNICODE --> LATIN7
+SELECT CONVERT('foo' USING utf8_to_iso8859_13);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN7');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN7 -> UNICODE
+-- LATIN7 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_13_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN7', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN8
+-- UNICODE --> LATIN8
+SELECT CONVERT('foo' USING utf8_to_iso8859_14);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN8');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN8 -> UNICODE
+-- LATIN8 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_14_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN8', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN9
+-- UNICODE --> LATIN9
+SELECT CONVERT('foo' USING utf8_to_iso8859_15);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN9');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN9 -> UNICODE
+-- LATIN9 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_15_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN9', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> LATIN10
+-- UNICODE --> LATIN10
+SELECT CONVERT('foo' USING utf8_to_iso8859_16);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'LATIN10');
  convert 
 ---------
  foo
 (1 row)
 
--- LATIN10 -> UNICODE
+-- LATIN10 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_16_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'LATIN10', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> ISO-8859-5
+-- UNICODE --> ISO-8859-5
+SELECT CONVERT('foo' USING utf8_to_iso8859_5);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-5');
  convert 
 ---------
  foo
 (1 row)
 
--- ISO-8859-5 -> UNICODE
+-- ISO-8859-5 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_5_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'ISO-8859-5', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> ISO-8859-6
+-- UNICODE --> ISO-8859-6
+SELECT CONVERT('foo' USING utf8_to_iso8859_6);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-6');
  convert 
 ---------
  foo
 (1 row)
 
--- ISO-8859-6 -> UNICODE
+-- ISO-8859-6 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_6_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'ISO-8859-6', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> ISO-8859-7
+-- UNICODE --> ISO-8859-7
+SELECT CONVERT('foo' USING utf8_to_iso8859_7);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-7');
  convert 
 ---------
  foo
 (1 row)
 
--- ISO-8859-7 -> UNICODE
+-- ISO-8859-7 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_7_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'ISO-8859-7', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- UNICODE -> ISO-8859-8
+-- UNICODE --> ISO-8859-8
+SELECT CONVERT('foo' USING utf8_to_iso8859_8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-8');
  convert 
 ---------
  foo
 (1 row)
 
--- ISO-8859-8 -> UNICODE
+-- ISO-8859-8 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_8_to_utf8);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'ISO-8859-8', 'UNICODE');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_JP -> SJIS
+-- EUC_JP --> SJIS
+SELECT CONVERT('foo' USING euc_jp_to_sjis);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_JP', 'SJIS');
  convert 
 ---------
  foo
 (1 row)
 
--- SJIS -> EUC_JP
+-- SJIS --> EUC_JP
+SELECT CONVERT('foo' USING sjis_to_euc_jp);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'SJIS', 'EUC_JP');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_JP -> MULE_INTERNAL
+-- EUC_JP --> MULE_INTERNAL
+SELECT CONVERT('foo' USING euc_jp_to_mic);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_JP', 'MULE_INTERNAL');
  convert 
 ---------
  foo
 (1 row)
 
--- SJIS -> MULE_INTERNAL
+-- SJIS --> MULE_INTERNAL
+SELECT CONVERT('foo' USING sjis_to_mic);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'SJIS', 'MULE_INTERNAL');
  convert 
 ---------
  foo
 (1 row)
 
--- MULE_INTERNAL -> EUC_JP
+-- MULE_INTERNAL --> EUC_JP
+SELECT CONVERT('foo' USING mic_to_euc_jp);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'EUC_JP');
  convert 
 ---------
  foo
 (1 row)
 
--- MULE_INTERNAL -> SJIS
+-- MULE_INTERNAL --> SJIS
+SELECT CONVERT('foo' USING mic_to_sjis);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'SJIS');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_TW -> BIG5
+-- EUC_TW --> BIG5
+SELECT CONVERT('foo' USING euc_tw_to_big5);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_TW', 'BIG5');
  convert 
 ---------
  foo
 (1 row)
 
--- BIG5 -> EUC_TW
+-- BIG5 --> EUC_TW
+SELECT CONVERT('foo' USING big5_to_euc_tw);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'BIG5', 'EUC_TW');
  convert 
 ---------
  foo
 (1 row)
 
--- EUC_TW -> MULE_INTERNAL
+-- EUC_TW --> MULE_INTERNAL
+SELECT CONVERT('foo' USING euc_tw_to_mic);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'EUC_TW', 'MULE_INTERNAL');
  convert 
 ---------
  foo
 (1 row)
 
--- BIG5 -> MULE_INTERNAL
+-- BIG5 --> MULE_INTERNAL
+SELECT CONVERT('foo' USING big5_to_mic);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'BIG5', 'MULE_INTERNAL');
  convert 
 ---------
  foo
 (1 row)
 
--- MULE_INTERNAL -> EUC_TW
+-- MULE_INTERNAL --> EUC_TW
+SELECT CONVERT('foo' USING mic_to_euc_tw);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'EUC_TW');
  convert 
 ---------
  foo
 (1 row)
 
--- MULE_INTERNAL -> BIG5
+-- MULE_INTERNAL --> BIG5
+SELECT CONVERT('foo' USING mic_to_big5);
+ convert 
+---------
+ foo
+(1 row)
+
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'BIG5');
  convert 
 ---------
  foo
 (1 row)
 
+--
+-- return to the super user
+--
 RESET SESSION AUTHORIZATION;
 DROP USER foo;
diff --git a/src/test/regress/sql/conversion.sql b/src/test/regress/sql/conversion.sql
index 7be4916fec0..e4639d86278 100644
--- a/src/test/regress/sql/conversion.sql
+++ b/src/test/regress/sql/conversion.sql
@@ -23,134 +23,200 @@ DROP CONVERSION myconv;
 DROP CONVERSION mydef;
 --
 -- make sure all pre-defined conversions are fine.
---
--- UNICODE -> SQL_ASCII
+-- UNICODE --> SQL_ASCII
+SELECT CONVERT('foo' USING utf8_to_ascii);
 SELECT CONVERT('foo', 'UNICODE', 'SQL_ASCII');
--- SQL_ASCII -> UNICODE
+-- SQL_ASCII --> UNICODE
+SELECT CONVERT('foo' USING ascii_to_utf8);
 SELECT CONVERT('foo', 'SQL_ASCII', 'UNICODE');
--- UNICODE -> LATIN1
+-- UNICODE --> LATIN1
+SELECT CONVERT('foo' USING utf8_to_iso8859_1);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN1');
--- LATIN1 -> UNICODE
+-- LATIN1 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_1_to_utf8);
 SELECT CONVERT('foo', 'LATIN1', 'UNICODE');
--- EUC_JP -> UNICODE
+-- EUC_JP --> UNICODE
+SELECT CONVERT('foo' USING euc_jp_to_utf8);
 SELECT CONVERT('foo', 'EUC_JP', 'UNICODE');
--- UNICODE -> EUC_JP
+-- UNICODE --> EUC_JP
+SELECT CONVERT('foo' USING utf8_to_euc_jp);
 SELECT CONVERT('foo', 'UNICODE', 'EUC_JP');
--- EUC_KR -> UNICODE
+-- EUC_KR --> UNICODE
+SELECT CONVERT('foo' USING euc_kr_to_utf8);
 SELECT CONVERT('foo', 'EUC_KR', 'UNICODE');
--- UNICODE -> EUC_KR
+-- UNICODE --> EUC_KR
+SELECT CONVERT('foo' USING utf8_to_euc_kr);
 SELECT CONVERT('foo', 'UNICODE', 'EUC_KR');
--- EUC_CN -> UNICODE
+-- EUC_CN --> UNICODE
+SELECT CONVERT('foo' USING euc_cn_to_utf8);
 SELECT CONVERT('foo', 'EUC_CN', 'UNICODE');
--- UNICODE -> EUC_CN
+-- UNICODE --> EUC_CN
+SELECT CONVERT('foo' USING utf8_to_euc_cn);
 SELECT CONVERT('foo', 'UNICODE', 'EUC_CN');
--- EUC_TW -> UNICODE
+-- EUC_TW --> UNICODE
+SELECT CONVERT('foo' USING euc_tw_to_utf8);
 SELECT CONVERT('foo', 'EUC_TW', 'UNICODE');
--- UNICODE -> EUC_TW
+-- UNICODE --> EUC_TW
+SELECT CONVERT('foo' USING utf8_to_euc_tw);
 SELECT CONVERT('foo', 'UNICODE', 'EUC_TW');
--- SJIS -> UNICODE
+-- SJIS --> UNICODE
+SELECT CONVERT('foo' USING sjis_to_utf8);
 SELECT CONVERT('foo', 'SJIS', 'UNICODE');
--- UNICODE -> SJIS
+-- UNICODE --> SJIS
+SELECT CONVERT('foo' USING utf8_to_sjis);
 SELECT CONVERT('foo', 'UNICODE', 'SJIS');
--- BIG5 -> UNICODE
+-- BIG5 --> UNICODE
+SELECT CONVERT('foo' USING big5_to_utf8);
 SELECT CONVERT('foo', 'BIG5', 'UNICODE');
--- UNICODE -> BIG5
+-- UNICODE --> BIG5
+SELECT CONVERT('foo' USING utf8_to_big5);
 SELECT CONVERT('foo', 'UNICODE', 'BIG5');
--- GBK -> UNICODE
+-- GBK --> UNICODE
+SELECT CONVERT('foo' USING gbk_to_utf8);
 SELECT CONVERT('foo', 'GBK', 'UNICODE');
--- UNICODE -> GBK
+-- UNICODE --> GBK
+SELECT CONVERT('foo' USING utf8_to_gbk);
 SELECT CONVERT('foo', 'UNICODE', 'GBK');
--- GB18030 -> UNICODE
+-- GB18030 --> UNICODE
+SELECT CONVERT('foo' USING gb18030_to_utf8);
 SELECT CONVERT('foo', 'GB18030', 'UNICODE');
--- UNICODE -> GB18030
+-- UNICODE --> GB18030
+SELECT CONVERT('foo' USING utf8_to_gb18030);
 SELECT CONVERT('foo', 'UNICODE', 'GB18030');
--- UHC -> UNICODE
+-- UHC --> UNICODE
+SELECT CONVERT('foo' USING uhc_to_utf8);
 SELECT CONVERT('foo', 'UHC', 'UNICODE');
--- UNICODE -> UHC
+-- UNICODE --> UHC
+SELECT CONVERT('foo' USING utf8_to_uhc);
 SELECT CONVERT('foo', 'UNICODE', 'UHC');
--- JOHAB -> UNICODE
+-- JOHAB --> UNICODE
+SELECT CONVERT('foo' USING johab_to_utf8);
 SELECT CONVERT('foo', 'JOHAB', 'UNICODE');
--- UNICODE -> JOHAB
+-- UNICODE --> JOHAB
+SELECT CONVERT('foo' USING utf8_to_johab);
 SELECT CONVERT('foo', 'UNICODE', 'JOHAB');
--- TCVN -> UNICODE
+-- TCVN --> UNICODE
+SELECT CONVERT('foo' USING tcvn_to_utf8);
 SELECT CONVERT('foo', 'TCVN', 'UNICODE');
--- UNICODE -> TCVN
+-- UNICODE --> TCVN
+SELECT CONVERT('foo' USING utf8_to_tcvn);
 SELECT CONVERT('foo', 'UNICODE', 'TCVN');
--- UNICODE -> LATIN2
+-- UNICODE --> LATIN2
+SELECT CONVERT('foo' USING utf8_to_iso8859_2);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN2');
--- LATIN2 -> UNICODE
+-- LATIN2 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_2_to_utf8);
 SELECT CONVERT('foo', 'LATIN2', 'UNICODE');
--- UNICODE -> LATIN3
+-- UNICODE --> LATIN3
+SELECT CONVERT('foo' USING utf8_to_iso8859_3);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN3');
--- LATIN3 -> UNICODE
+-- LATIN3 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_3_to_utf8);
 SELECT CONVERT('foo', 'LATIN3', 'UNICODE');
--- UNICODE -> LATIN4
+-- UNICODE --> LATIN4
+SELECT CONVERT('foo' USING utf8_to_iso8859_4);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN4');
--- LATIN4 -> UNICODE
+-- LATIN4 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_4_to_utf8);
 SELECT CONVERT('foo', 'LATIN4', 'UNICODE');
--- UNICODE -> LATIN5
+-- UNICODE --> LATIN5
+SELECT CONVERT('foo' USING utf8_to_iso8859_9);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN5');
--- LATIN5 -> UNICODE
+-- LATIN5 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_9_to_utf8);
 SELECT CONVERT('foo', 'LATIN5', 'UNICODE');
--- UNICODE -> LATIN6
+-- UNICODE --> LATIN6
+SELECT CONVERT('foo' USING utf8_to_iso8859_10);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN6');
--- LATIN6 -> UNICODE
+-- LATIN6 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_10_to_utf8);
 SELECT CONVERT('foo', 'LATIN6', 'UNICODE');
--- UNICODE -> LATIN7
+-- UNICODE --> LATIN7
+SELECT CONVERT('foo' USING utf8_to_iso8859_13);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN7');
--- LATIN7 -> UNICODE
+-- LATIN7 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_13_to_utf8);
 SELECT CONVERT('foo', 'LATIN7', 'UNICODE');
--- UNICODE -> LATIN8
+-- UNICODE --> LATIN8
+SELECT CONVERT('foo' USING utf8_to_iso8859_14);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN8');
--- LATIN8 -> UNICODE
+-- LATIN8 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_14_to_utf8);
 SELECT CONVERT('foo', 'LATIN8', 'UNICODE');
--- UNICODE -> LATIN9
+-- UNICODE --> LATIN9
+SELECT CONVERT('foo' USING utf8_to_iso8859_15);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN9');
--- LATIN9 -> UNICODE
+-- LATIN9 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_15_to_utf8);
 SELECT CONVERT('foo', 'LATIN9', 'UNICODE');
--- UNICODE -> LATIN10
+-- UNICODE --> LATIN10
+SELECT CONVERT('foo' USING utf8_to_iso8859_16);
 SELECT CONVERT('foo', 'UNICODE', 'LATIN10');
--- LATIN10 -> UNICODE
+-- LATIN10 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_16_to_utf8);
 SELECT CONVERT('foo', 'LATIN10', 'UNICODE');
--- UNICODE -> ISO-8859-5
+-- UNICODE --> ISO-8859-5
+SELECT CONVERT('foo' USING utf8_to_iso8859_5);
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-5');
--- ISO-8859-5 -> UNICODE
+-- ISO-8859-5 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_5_to_utf8);
 SELECT CONVERT('foo', 'ISO-8859-5', 'UNICODE');
--- UNICODE -> ISO-8859-6
+-- UNICODE --> ISO-8859-6
+SELECT CONVERT('foo' USING utf8_to_iso8859_6);
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-6');
--- ISO-8859-6 -> UNICODE
+-- ISO-8859-6 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_6_to_utf8);
 SELECT CONVERT('foo', 'ISO-8859-6', 'UNICODE');
--- UNICODE -> ISO-8859-7
+-- UNICODE --> ISO-8859-7
+SELECT CONVERT('foo' USING utf8_to_iso8859_7);
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-7');
--- ISO-8859-7 -> UNICODE
+-- ISO-8859-7 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_7_to_utf8);
 SELECT CONVERT('foo', 'ISO-8859-7', 'UNICODE');
--- UNICODE -> ISO-8859-8
+-- UNICODE --> ISO-8859-8
+SELECT CONVERT('foo' USING utf8_to_iso8859_8);
 SELECT CONVERT('foo', 'UNICODE', 'ISO-8859-8');
--- ISO-8859-8 -> UNICODE
+-- ISO-8859-8 --> UNICODE
+SELECT CONVERT('foo' USING iso8859_8_to_utf8);
 SELECT CONVERT('foo', 'ISO-8859-8', 'UNICODE');
--- EUC_JP -> SJIS
+-- EUC_JP --> SJIS
+SELECT CONVERT('foo' USING euc_jp_to_sjis);
 SELECT CONVERT('foo', 'EUC_JP', 'SJIS');
--- SJIS -> EUC_JP
+-- SJIS --> EUC_JP
+SELECT CONVERT('foo' USING sjis_to_euc_jp);
 SELECT CONVERT('foo', 'SJIS', 'EUC_JP');
--- EUC_JP -> MULE_INTERNAL
+-- EUC_JP --> MULE_INTERNAL
+SELECT CONVERT('foo' USING euc_jp_to_mic);
 SELECT CONVERT('foo', 'EUC_JP', 'MULE_INTERNAL');
--- SJIS -> MULE_INTERNAL
+-- SJIS --> MULE_INTERNAL
+SELECT CONVERT('foo' USING sjis_to_mic);
 SELECT CONVERT('foo', 'SJIS', 'MULE_INTERNAL');
--- MULE_INTERNAL -> EUC_JP
+-- MULE_INTERNAL --> EUC_JP
+SELECT CONVERT('foo' USING mic_to_euc_jp);
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'EUC_JP');
--- MULE_INTERNAL -> SJIS
+-- MULE_INTERNAL --> SJIS
+SELECT CONVERT('foo' USING mic_to_sjis);
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'SJIS');
--- EUC_TW -> BIG5
+-- EUC_TW --> BIG5
+SELECT CONVERT('foo' USING euc_tw_to_big5);
 SELECT CONVERT('foo', 'EUC_TW', 'BIG5');
--- BIG5 -> EUC_TW
+-- BIG5 --> EUC_TW
+SELECT CONVERT('foo' USING big5_to_euc_tw);
 SELECT CONVERT('foo', 'BIG5', 'EUC_TW');
--- EUC_TW -> MULE_INTERNAL
+-- EUC_TW --> MULE_INTERNAL
+SELECT CONVERT('foo' USING euc_tw_to_mic);
 SELECT CONVERT('foo', 'EUC_TW', 'MULE_INTERNAL');
--- BIG5 -> MULE_INTERNAL
+-- BIG5 --> MULE_INTERNAL
+SELECT CONVERT('foo' USING big5_to_mic);
 SELECT CONVERT('foo', 'BIG5', 'MULE_INTERNAL');
--- MULE_INTERNAL -> EUC_TW
+-- MULE_INTERNAL --> EUC_TW
+SELECT CONVERT('foo' USING mic_to_euc_tw);
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'EUC_TW');
--- MULE_INTERNAL -> BIG5
+-- MULE_INTERNAL --> BIG5
+SELECT CONVERT('foo' USING mic_to_big5);
 SELECT CONVERT('foo', 'MULE_INTERNAL', 'BIG5');
+--
+-- return to the super user
+--
 RESET SESSION AUTHORIZATION;
 DROP USER foo;
-- 
GitLab