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