webrama.pl
webrama.pl

Reputation: 1890

PgSQL trim whole string at end, not every characters

i'm trying to rebuild relations in my DB. I need to "repair" some strings that are stored badly in my table named city_list.

The data:

"Berlin"

"London "

"Kijev&nbsp"

"Poznan&nbsp"

I used pgsql function rtrim(string text [, characters text]) in that way:

UPDATE city_list SET city_name=RTrim(city_name);
UPDATE city_list SET city_name=RTrim(city_name, ' ');

Now I have:

"Berlin"

"Londo"

"Kijev"

"Pozna"

Is there way to force rtrim to cut whole " " string from end not every single characters?

Upvotes: 1

Views: 2231

Answers (1)

Denis de Bernardy
Denis de Bernardy

Reputation: 78413

Use regexp_replace().

The trim() function's second argument is the full list of chars to be trimmed.

Upvotes: 4

Related Questions