convert function - Mailing list pgsql-hackers

From Tatsuo Ishii
Subject convert function
Date
Msg-id 20010815160902N.t-ishii@sra.co.jp
Whole thread Raw
Responses Re: convert function
Re: convert function
List pgsql-hackers
I have added new function called "convert" similar to SQL99's convert.
Convert converts encoding according to parameters. For example, if you
have a table named "unicode" in an Unicode database,

SELECT convert(text_field, 'LATIN1') FROM unicode;

will return text in ISO-8859-1 representation. This is not very
impressive because PGCLIENTENCODING could do same thing. However
consider a table:

CREATE TABLE mixed (      french TEXT,    -- ISO-8859-1      czech TEXT    -- ISO-8859-2
);

Those columns hold texts in different language. Since we do not have
NCHAR yet, we cannot extract data from "mixed" very well (note that we
could store french and czech data by INSERT french and then UPDATE
czech, so on. Even we could store them at once actually since they are
"binary compatible.") However, using convert, (and if you have an
Unicode aware termminal), you could view them:

SELECT convert(french, 'LATIN1', 'UNICODE'),      convert(czech, 'LATIN2', 'UNICODE') FROM unicode;

Convert is especially usefull if you want to sort Unicode data
according to a specific locale. For example:

SELECT * FROM unicode order by convert(text_field, 'LATIN1');

should return data in proper sort order if you enable European locale.
Note that to make above possible, you will need to turn on all of
--enable-multibyte, --enable-locale, --enable-unicode-conversion
options.

See Table 4-7 in the string function section in the docs for more
details.

Testings are welcome. I only understand Japanese and English!
--
Tatsuo Ishii



pgsql-hackers by date:

Previous
From: "maruthi maruthi"
Date:
Subject: Transaction id increment
Next
From: John Anderson
Date:
Subject: Re: MS interview