为什么Postgres 9.3中的trim没有完成这项工作?

use*_*363 3 sql postgresql trim

我们想resource在 postgres 9.3 中修剪列的前导和尾随空间,这似乎是一个简单的工作。这是 SQL:

update tablename set resource=trim(resource);
Run Code Online (Sandbox Code Playgroud)

查询在 postgres 管理工具 SQL 屏幕中成功执行。然而,空间并没有被修剪。然后我们通过指定id执行SQL:

update tablename set resource=trim(resource) where id=723;
Run Code Online (Sandbox Code Playgroud)

它返回:

Query returned successfully: one row affected, 12 ms execution time.
Run Code Online (Sandbox Code Playgroud)

但结果是一样的,没有更新。在终端窗口中执行相同的 SQL,但没有任何反应。

为什么trim不在这里工作?

Gor*_*off 6

想必,你看到的角色并不是一个实际的空间。您可以使用以下命令查看它的 ASCII 代码:

select ascii(left(resource, 1))
from tablename
where id = 723;
Run Code Online (Sandbox Code Playgroud)

如果你只想删除第一个字符,你可以这样做:

update tablename
    set resource = substring(resource from 2)
    where id = 723;
Run Code Online (Sandbox Code Playgroud)