convert function

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: convert function
Date: 2001-08-15 07:09:02
Message-ID: 20010815160902N.t-ishii@sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Anderson 2001-08-15 08:39:24 Re: MS interview
Previous Message maruthi maruthi 2001-08-15 06:54:48 Transaction id increment