我创建了一个名称中带有 unicode 字符的表(专门用 unicode 测试表名)。它很好地创建了表,但是我检测表是否存在的方法坏了!
这是有问题的交互:
caribou_test=# select table_name from information_schema.tables where table_schema = 'public';
table_name
-------------
...
pinkpink1
(16 rows)
caribou_test=# select table_name from information_schema.tables where table_schema = 'public' and table_name = 'pinkƒpink1';
table_name
------------
(0 rows)
caribou_test=# select table_name from information_schema.tables where table_schema = 'public' and table_name = 'pinkpink1';
table_name
------------
(0 rows)
caribou_test=# select * from pinkƒpink1;
id | position | env_id | locked | created_at | updated_at | status_id | status_position | i1l0 | f∆ | growth555
----+----------+--------+--------+----------------------------+-------------------------+-----------+-----------------+-------+-------+--------------
1 | 0 | 1 | f | 2013-06-27 14:50:34.228136 | 2013-06-27 14:50:34.227 | 1 | 0 | YELLL | 55555 | 1.3333388822
(1 row)
表名是pinkƒpink1(测试数据)。如您所见,当我从 information_schema.tables 中选择表名时,它显示时没有 ƒ,但我无法选择表名!但我仍然可以直接向该表发出选择。这里发生了什么?
编辑:为@craig-ringer 提供所需的信息:
caribou_test=# SELECT current_setting('server_encoding') AS server_encoding, current_setting('client_encoding') AS client_encoding, version();
server_encoding | client_encoding | version
-----------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------
UTF8 | UTF8 | PostgreSQL 9.2.2 on x86_64-apple-darwin12.2.1, compiled by Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn), 64-bit
caribou_test=# SELECT * FROM pg_class WHERE relname = 'pinkƑpink1';
---> (0 rows)
caribou_test=# SELECT upper('ƒ') = 'Ƒ', lower('Ƒ') = 'ƒ';
?column? | ?column?
----------+----------
t | t
(1 row)
caribou_test=# WITH chars(rowid, thechar) AS (VALUES (1,'ƒ'),(2,'Ƒ'),(3,upper('ƒ')),(4,lower('Ƒ'))) SELECT rowid, thechar, convert_to(thechar, 'utf-8') from chars;
rowid | thechar | convert_to
-------+---------+------------
1 | ƒ | \xc692
2 | Ƒ | \xc691
3 | Ƒ | \xc691
4 | ƒ | \xc692