为什么这个查询增加了额外的长度 upper(trim(LEFT(col_name::varchar, 100)))

why this query added extra length upper(trim(LEFT(col_name::varchar, 100)))

select
    distinct upper(trim(LEFT(col_name::varchar, 100))) as col_name from mytable;

从 LEFT(col_name::varchar, 100) returns 左起 100 个字符开始,不知何故增加了额外的长度。

而且我在插入另一个时出现以下错误table

ERROR: String of 101 octets is too long for type Varchar(100) If anyone could help me in understanding this behaviour

LEFT(string, N) 函数returns N 个字符 从一个字符串的左侧开始。

然而,这 N 个字符可能需要超过 N 个字节 (octects),例如重音字符:

dbadmin=> select left('é', 1);
 left
------
 é

dbadmin=> select octet_length(left('é', 1));
 octet_length
--------------
            2