diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index dfebb45e1b..aed47db79b 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1,5 +1,5 @@
@@ -857,6 +857,19 @@ PostgreSQL documentation
4
+
+ convert(string
+ using conversion_name)
+ text
+ Change encoding using specified conversion name.
+ Conversions can be defined by CREATE CONVERSION.
+ Also there are some pre-defined conversion names.
+ See for available
+ conversion names.
+ convert('PostgreSQL' using iso8859_1_to_utf8)
+ 'PostgreSQL' in UNICODE(UTF-8) encoding
+
+
lower(string)
text
@@ -947,6 +960,405 @@ PostgreSQL documentation
+
+ Available conversion names
+
+
+
+ conversion
+ source encoding
+ destination encoding
+
+
+
+
+ ascii_to_utf8
+ SQL_ASCII
+ UNICODE
+
+
+
+ big5_to_euc_tw
+ BIG5
+ EUC_TW
+
+
+
+ big5_to_mic
+ BIG5
+ MULE_INTERNAL
+
+
+
+ big5_to_utf8
+ BIG5
+ UNICODE
+
+
+
+ euc_cn_to_utf8
+ EUC_CN
+ UNICODE
+
+
+
+ euc_jp_to_mic
+ EUC_JP
+ MULE_INTERNAL
+
+
+
+ euc_jp_to_sjis
+ EUC_JP
+ SJIS
+
+
+
+ euc_jp_to_utf8
+ EUC_JP
+ UNICODE
+
+
+
+ euc_kr_to_utf8
+ EUC_KR
+ UNICODE
+
+
+
+ euc_tw_to_big5
+ EUC_TW
+ BIG5
+
+
+
+ euc_tw_to_mic
+ EUC_TW
+ MULE_INTERNAL
+
+
+
+ euc_tw_to_utf8
+ EUC_TW
+ UNICODE
+
+
+
+ gb18030_to_utf8
+ GB18030
+ UNICODE
+
+
+
+ gbk_to_utf8
+ GBK
+ UNICODE
+
+
+
+ iso8859_10_to_utf8
+ LATIN6
+ UNICODE
+
+
+
+ iso8859_13_to_utf8
+ LATIN7
+ UNICODE
+
+
+
+ iso8859_14_to_utf8
+ LATIN8
+ UNICODE
+
+
+
+ iso8859_15_to_utf8
+ LATIN9
+ UNICODE
+
+
+
+ iso8859_16_to_utf8
+ LATIN10
+ UNICODE
+
+
+
+ iso8859_1_to_utf8
+ LATIN1
+ UNICODE
+
+
+
+ iso8859_2_to_utf8
+ LATIN2
+ UNICODE
+
+
+
+ iso8859_3_to_utf8
+ LATIN3
+ UNICODE
+
+
+
+ iso8859_4_to_utf8
+ LATIN4
+ UNICODE
+
+
+
+ iso8859_5_to_utf8
+ ISO_8859_5
+ UNICODE
+
+
+
+ iso8859_6_to_utf8
+ ISO_8859_6
+ UNICODE
+
+
+
+ iso8859_7_to_utf8
+ ISO_8859_7
+ UNICODE
+
+
+
+ iso8859_8_to_utf8
+ ISO_8859_8
+ UNICODE
+
+
+
+ iso8859_9_to_utf8
+ LATIN5
+ UNICODE
+
+
+
+ johab_to_utf8
+ JOHAB
+ UNICODE
+
+
+
+ mic_to_big5
+ MULE_INTERNAL
+ BIG5
+
+
+
+ mic_to_euc_jp
+ MULE_INTERNAL
+ EUC_JP
+
+
+
+ mic_to_euc_tw
+ MULE_INTERNAL
+ EUC_TW
+
+
+
+ mic_to_sjis
+ MULE_INTERNAL
+ SJIS
+
+
+
+ sjis_to_euc_jp
+ SJIS
+ EUC_JP
+
+
+
+ sjis_to_mic
+ SJIS
+ MULE_INTERNAL
+
+
+
+ sjis_to_utf8
+ SJIS
+ UNICODE
+
+
+
+ tcvn_to_utf8
+ TCVN
+ UNICODE
+
+
+
+ uhc_to_utf8
+ UHC
+ UNICODE
+
+
+
+ utf8_to_ascii
+ UNICODE
+ SQL_ASCII
+
+
+
+ utf8_to_big5
+ UNICODE
+ BIG5
+
+
+
+ utf8_to_euc_cn
+ UNICODE
+ EUC_CN
+
+
+
+ utf8_to_euc_jp
+ UNICODE
+ EUC_JP
+
+
+
+ utf8_to_euc_kr
+ UNICODE
+ EUC_KR
+
+
+
+ utf8_to_euc_tw
+ UNICODE
+ EUC_TW
+
+
+
+ utf8_to_gb18030
+ UNICODE
+ GB18030
+
+
+
+ utf8_to_gbk
+ UNICODE
+ GBK
+
+
+
+ utf8_to_iso8859_1
+ UNICODE
+ LATIN1
+
+
+
+ utf8_to_iso8859_10
+ UNICODE
+ LATIN6
+
+
+
+ utf8_to_iso8859_13
+ UNICODE
+ LATIN7
+
+
+
+ utf8_to_iso8859_14
+ UNICODE
+ LATIN8
+
+
+
+ utf8_to_iso8859_15
+ UNICODE
+ LATIN9
+
+
+
+ utf8_to_iso8859_16
+ UNICODE
+ LATIN10
+
+
+
+ utf8_to_iso8859_2
+ UNICODE
+ LATIN2
+
+
+
+ utf8_to_iso8859_3
+ UNICODE
+ LATIN3
+
+
+
+ utf8_to_iso8859_4
+ UNICODE
+ LATIN4
+
+
+
+ utf8_to_iso8859_5
+ UNICODE
+ ISO_8859_5
+
+
+
+ utf8_to_iso8859_6
+ UNICODE
+ ISO_8859_6
+
+
+
+ utf8_to_iso8859_7
+ UNICODE
+ ISO_8859_7
+
+
+
+ utf8_to_iso8859_8
+ UNICODE
+ ISO_8859_8
+
+
+
+ utf8_to_iso8859_9
+ UNICODE
+ LATIN5
+
+
+
+ utf8_to_johab
+ UNICODE
+ JOHAB
+
+
+
+ utf8_to_sjis
+ UNICODE
+ SJIS
+
+
+
+ utf8_to_tcvn
+ UNICODE
+ TCVN
+
+
+
+ utf8_to_uhc
+ UNICODE
+ UHC
+
+
+
+
+
+
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 0425e44c1c..bc2098034f 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 c422e33e31..7dfd0679a2 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
+ * USING
+ *
+ * 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 5c77aebfe6..f57f461124 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 into_clause, OptTempTableName
@@ -232,7 +234,7 @@ static void doNegateFloat(Value *v);
%type join_type
%type extract_list, overlay_list, position_list
-%type substr_list, trim_list
+%type substr_list, trim_list, convert_list
%type opt_interval
%type 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 32733d8f54..2ae62ac18d 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 64b60a510a..ea460aa529 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 30ff138408..a1ab66bc28 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 0000000000..da8238b9f3
--- /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 0000000000..62a90d20b6
--- /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 12669ed78d..f3dfa81879 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 bd0f176f28..f7e4ec32fd 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 de08137bff..e250d6d5d0 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 3520af4cec..afd8a782cc 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 d1b3cdfba8..f1f496464b 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 7be4916fec..e4639d8627 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;