sql - SQL 长度函数如何处理 unicode 字素?

标签 sql postgresql unicode grapheme

考虑以下场景,其中我有 \U00000045\U00000301 定义的字符串 É

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'\U00000045\U00000301'))
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)

关于sql - SQL 长度函数如何处理 unicode 字素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48236245/

相关文章:

ruby-on-rails - 用于删除反斜杠的 Postgres 命令在控制台中有效,但不适用于 ActiveRecord::Base.connection.execute

mysql - 对三个表进行计数和求和,获取用户信息及其点赞数

postgresql - 双向复制设计 : best way to script and execute unmatched row on Source DB to multiple subscriber DBs, 顺序还是并发?

iphone - SQLite Select 语句的更好性能

django - 无法从 dockerized 应用程序连接到 docker 中的 postgres 服务器

python - 字符串文字 Vs Unicode 文字 Vs unicode 类型对象 - 内存表示

css - 谷歌字体和跨浏览器 Unicode

regex - 如何规范/关联Google表格中的Unicode字符?

sql - RegEx:字符串中重复相同的元音 - Oracle SQL

mysql - SQL 查询 : get data from multiple table with joining each other with common field but no guarantee any table have data for sure.