Thread: Removing spaces
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.
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
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