【问题标题】:Postgresql character varying strange behaviourPostgresql 字符变化奇怪的行为
【发布时间】:2018-03-14 15:52:25
【问题描述】:

我有一张表,其中client_codecharacter varying(10) 列。

现在,这个查询不起作用:

insert into mydb.mytable (CLIENT_CODE) values ('0123456789');

我收到ERROR: value too long for type character varying(10)

在查询中放入 9 个字符时,它运行良好。

我觉得很奇怪。我读过的不是the definition of character varying

我将 PostgreSQL 9.3.19 与 ENCODING = 'UTF8'LC_CTYPE = 'French_France.1252' 一起使用。

【问题讨论】:

  • 你能把select * from information_schema.columns where column_name = 'client_code';的输出贴出来

标签: postgresql character-encoding varchar


【解决方案1】:

第 1 行下方是复制粘贴您的字符串,第 2 行是我手动插入的:

t=# with d(s,t) as (values(1,'0123456789'),(2,'0123456789'))
select *,char_length(t),ascii(t),ascii(substring(t,2,1)) from d;
 s |     t      | char_length | ascii | ascii
---+------------+-------------+-------+-------
 1 | 0123456789 |          11 | 65279 |    48
 2 | 0123456789 |          10 |    48 |    49
(2 rows)

你有 http://www.fileformat.info/info/unicode/char/feff/index.htm ZERO WIDTH NO-BREAK SPACE 作为第一个字符 - 你看不到它,但 postgres 有

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 2021-01-17
    • 2012-02-02
    • 2023-03-09
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 2013-09-09
    相关资源
    最近更新 更多