- 論壇徽章:
- 0
|
我在數(shù)據(jù)庫插入數(shù)據(jù)的過程中偶然發(fā)現(xiàn),漢字“太陽”和“天隊(duì)”在pg里居然作為關(guān)鍵字是相同的...
我的客戶端是GBK,服務(wù)端是Unicode.
$ pg_config --version
PostgreSQL 7.4.8
$ echo "太陽" >; /tmp/tmp1
$ echo "天隊(duì)" >; /tmp/tmp2
$ iconv -f GBK -t UTF-8 /tmp/tmp1 | hexdump
0000000 a4e5 e9aa b398 000a
0000007
$ iconv -f GBK -t UTF-8 /tmp/tmp2 | hexdump
0000000 a4e5 e9a9 9f98 000a
0000007
$ psql html
html=>; set client_encoding='GBK';
SET
html=>; show server_encoding;
server_encoding
-----------------
UNICODE
(1 行)
html=>; show client_encoding;
client_encoding
-----------------
GBK
(1 行)
html=>; create table gbk (key varchar(64), value integer);
CREATE TABLE
html=>; insert into gbk values ('太陽', 1);
INSERT 2836917 1
html=>; insert into gbk values ('月亮', 2);
INSERT 2836918 1
html=>; insert into gbk values ('草原', 3);
INSERT 2836919 1
html=>; insert into gbk values ('天隊(duì)', 4);
INSERT 2836920 1
html=>; select * from gbk;
key | value
------+-------
太陽 | 1
月亮 | 2
草原 | 3
天隊(duì) | 4
(4 行)
html=>; select * from gbk where key='草原';
key | value
------+-------
草原 | 3
(1 行)
html=>; select * from gbk where key='太陽';
key | value
------+-------
太陽 | 1
天隊(duì) | 4
(2 行)
html=>; \q
-------------------------------------------------------------
為什么會(huì)這樣? |
|