Subject Re: Removing trailing spaces from varchar
Author Adam
--- In firebird-support@yahoogroups.com, "Alan McDonald" <alan@m...>
wrote:
> >
> > Hi, is there a way to remove trailing spaces from a varchar,
preferably
> > using a trigger?
> >
> > For example:
> >
> > ID = 'XYZ ';
> >
> > should be converted to: ID = 'XYZ';
> >
> > Are there any functions for doing this?
> >
> > Thanks
> >
>
> F_STRIPSTRING works for me. It's in the FreeUDFLib
> Alan

Even easier, IB_UDF is included in the default firebird install

DECLARE EXTERNAL FUNCTION rtrim
CSTRING(255)
RETURNS CSTRING(255) FREE_IT
ENTRY_POINT 'IB_UDF_rtrim' MODULE_NAME 'ib_udf';

A simple

BEFORE INSERT OR UPDATE

trigger could have the single line

NEW.ID = rtrim(NEW.ID);

But consider using generators and bigint for primary key fields. I
imagine quite a lot of confusion could happen if the client program
thinks it knows the real primary key but in reality you have changed
it. It may end up with a foreign key violation when it tries to use
the string it thinks is the PK in another table.

Adam