gpt4 book ai didi

sql - PostgreSQL upper function on the ascii 152 character ("ÿ")

转载 作者:行者123 更新时间:2023-11-29 11:36:54 24 4
gpt4 key购买 nike

在 Windows 7 平台上,使用 PostgreSQL 版本 9.3.9,使用 PgAdmin 作为客户端,在包含例如“ÿÿÿ”返回 null。如果存储了三个值,例如

"ada"
"john"
"mole"
"ÿÿÿ"

除了包含 "ÿÿÿ" 的行外,它们都以大写形式返回;这一排什么都不给,null...

数据库编码方案是UTF8/UNICODE。设置“client_encoding”具有相同的值,UNICODE

这是数据库中的设置问题、操作系统问题还是错误在数据库中?有一些推荐的解决方法吗?

结果:

select thecol, upper(thecol), upper(thecol) is null, convert_to(thecol, 'UTF8'), current_setting('server_encoding') from thetable where ... 

是:

"Apps";"APPS";f;"Apps";"UTF8"
"All";"ALL";f;"All";"UTF8"
"Test";"TEST";f;"Test";"UTF8"
"ÿÿÿ";"";f;"\303\277\303\277\303\277";"UTF8"

pg_settings 的 lc_ 部分是:

"lc_collate";"Swedish_Sweden.1252";"Shows the collation order locale."
"lc_ctype";"Swedish_Sweden.1252";"Shows the character classification and case conversion locale."
"lc_messages";"Swedish_Sweden.1252";"Sets the language in which messages are displayed."
"lc_monetary";"Swedish_Sweden.1252";"Sets the locale for formatting monetary amounts."
"lc_numeric";"Swedish_Sweden.1252";"Sets the locale for formatting numbers."

select * from pg_database 的输出是:

"template1";10;6;"Swedish_Sweden.1252";"Swedish_Sweden.1252";t;t;-1;12130;668;1‌​;1663;"{=c/postgres,postgres=CTc/postgres}" 
"template0";10;6;"Swedish_Sweden.1252";"Swedish_Sweden.1252";t;f;-1;12130;668;1‌​;1663;"{=c/postgres,postgres=CTc/postgres}"
"postgres";10;6;"Swedish_Sweden.1252";"Swedish_Sweden.1252";f;t;-1;12130;668;1;‌​1663;""

9.4.4版本的实际创建数据库语句是:

CREATE DATABASE postgres
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'Swedish_Sweden.1252'
LC_CTYPE = 'Swedish_Sweden.1252'
CONNECTION LIMIT = -1;

最佳答案

我的猜测是 upper 函数使用了数据库的 LC_CTYPE 设置。带分音符的拉丁文小写字母 Y (U+00FF) 的大写是带分音符的拉丁文大写字母 Y' (U+0178),它不是 Windows 1252 代码页的一部分。

如果您先将字符串转换为 Unicode 格式,upper 函数可能会按预期工作:

SELECT upper(convert_to(thecol, 'UTF8')) ...

您可能应该为 LC_CTYPELC_COLLATE 使用不同的值。在 Linux 上,您将使用 sv_SE.UTF-8

尽管如此,我认为这是 Postgres 中的一个错误。如果无法在目标字符集中表示大写版本,最好保留 ÿ

关于sql - PostgreSQL upper function on the ascii 152 character ("ÿ"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32690370/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com