user938363
user938363

Reputation: 10360

Why trim in Postgres 9.3 did not do the work?

We want to trim the leading and trailing space for resource column in postgres 9.3 and it seems to be a simple job. Here is the SQL:

update tablename set resource=trim(resource);

The query is executed in postgres admin tool SQL screen successfully. However the space was not trimmed. Then we executed the SQL by specifying the id:

update tablename set resource=trim(resource) where id=723;

It returned:

Query returned successfully: one row affected, 12 ms execution time.

However the result is the same and there is no update. The same SQL is executed in terminal window and nothing happens.

Why trim did not work here?

Upvotes: 3

Views: 3862

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269953

Presumably, the character you see is not an actual space. You can see the ASCII code for it by using:

select ascii(left(resource, 1))
from tablename
where id = 723;

If you just want to get rid of the first character, you can do:

update tablename
    set resource = substring(resource from 2)
    where id = 723;

Upvotes: 6

Related Questions