Обсуждение: Removing spaces

Поиск
Список
Период
Сортировка

Removing spaces

От
Dave Smith
Дата:
I have a field of type text that has a value like

'hello   \nworld   \n'

I would like to remove the trailing blanks between the last character
and the newline. I would like to use replace with a regx  like
/[ ]+\n/\n/ but it does not seem to work.





Re: Removing spaces

От
"Ed L."
Дата:
On Wednesday February 19 2003 11:19, Dave Smith wrote:
> I have a field of type text that has a value like
>
> 'hello   \nworld   \n'
>
> I would like to remove the trailing blanks between the last
> character and the newline. I would like to use replace with a regx
> like /[ ]+\n/\n/ but it does not seem to work.

You might try combining UPDATE with some of the string functions;
trim() + '\n' comes to mind.

http://www.ca.postgresql.org/users-lounge/docs/7.3/postgres/functions-string.html

Ed


Re: Removing spaces

От
Fabrizio Mazzoni
Дата:
You could use the trim function in a plpgsql trigger function eg:

CREATE FUNCTION fn_tr_longpad() RETURNS trigger AS '
begin
NEW.a := trim(trailing '' '' from NEW.a);
return NEW;
end; '  LANGUAGE 'plpgsql';

CREATE TRIGGER tst_trigger BEFORE INSERT ON mytable FOR EACH ROW EXECUTE PROCEDURE fn_tr_longpad()

a is the name of the column you have to trim, change it to your needs

Regards,

Fabrizio Mazzoni