考虑以下情况,其中我的字符串É
由U00000045U00000301
定义。
1( https://www.fileformat.info/info/unicode/char/0045/index.htm
2( https://www.fileformat.info/info/unicode/char/0301/index.htm
受varchar(1)
约束的表是否会将其视为有效的 1 个字符输入。还是会因为它被视为 2 个字符的输入而被拒绝?
SQL 通常如何处理包含字素的字符串的长度?
我可能看起来很愚蠢这个查询,但仍然:
t=# with c(u) as (values( e'U00000045U00000301'))
select u, u::varchar(1), u::varchar(2),char_length(u), octet_length(u) from c;
u | u | u | char_length | octet_length
---+---+---+-------------+--------------
É | E | É | 2 | 3
(1 row)
编辑
t=# show server_encoding ;
server_encoding
-----------------
UTF8
(1 row)
t=# l+ t
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
------+-------+----------+---------+-------+-------------------+-------+------------+-------------
t | vao | UTF8 | C | UTF-8 | | 51 MB | pg_default |
(1 row)