在此作一些使用的總結
以下具體以 Big5 與 UTF8 編碼互換的操作方式為主。
[注意] UTF8 轉十六進位後是六個字母的編碼,Big5 轉十六進位後是四個字母的編碼
輸入 hex code
下面分別用 Big5 與 UTF8 的編碼輸入字,「你」
edb=# SHOW client_encoding;
client_encoding
-----------------
UTF8
(1 row)
edb=# SELECT convert_from(BYTEA '\xa741', 'big5'), convert_from(BYTEA '\xe4b
da0', 'utf8');
convert_from | convert_from
--------------+--------------
你 | 你
(1 row)
edb=# select convert_from(decode('e4bda0', 'hex'), 'utf-8');
convert_from
--------------
你
(1 row)
輸出 hex code
以下從中文字「你」分別輸出 Big5 與 UTF8 的編碼
edb=# SELECT convert('你'::BYTEA, 'utf8', 'big5');
convert
---------
\xa741
(1 row)
edb=# SELECT encode ( convert('你'::BYTEA, 'utf8', 'big5')::bytea, 'hex' );
encode
--------
a741
(1 row)
edb=# SELECT '你'::BYTEA;
bytea
----------
\xe4bda0
(1 row)
Hex Code 對應轉換
以下分別呈現
1) UTF8 編碼轉 Big5 編碼
2) Big5 編碼轉 UTF8 編碼
edb=# select convert(E'\xe4\xbd\xa0', 'utf8', 'big5');
convert
---------
\xa741
(1 row)
edb=# SELECT convert('\xa741', 'big5', 'utf8');
convert
----------
\xe4bda0
(1 row)
edb=# SELECT convert(decode('a741', 'hex'), 'big5', 'utf8');
convert
----------
\xe4bda0
(1 row)
由於 Greenplum 4.x 是基於 Postgres 8.3 以前的版本,因此還不支援 Unicode 編碼轉換(8.4 才引進 Backslash Escape Sequences,9.0 支援 Unicode Escape string)可能需要 Greenplum 5.x 才會支援~
參考
沒有留言:
張貼留言