Thread: trim(both) problem?

trim(both) problem?

From
Emi Lu
Date:
Hi,

Isn't this a bug about trim both.
 select trim(both '<BR/>' from '<BR/>ROI Engineering Inc.');        btrim
--------------------- OI Engineering Inc.
(1 row)


"R" is missing? How?

 version
------------------------------------------------------------------------- PostgreSQL 8.0.15 on i686-pc-linux-gnu,
compiledby GCC gcc (GCC) 3.3.2
 

Thank you!








Re: trim(both) problem?

From
Tom Lane
Date:
Emi Lu <emilu@encs.concordia.ca> writes:
>   select trim(both '<BR/>' from '<BR/>ROI Engineering Inc.');
>          btrim
> ---------------------
>   OI Engineering Inc.
> (1 row)

> "R" is missing? How?

The first argument of trim is a set, not a sequence --- it means trim
any characters belonging to this set.
        regards, tom lane


Re: trim(both) problem?

From
Stephan Szabo
Date:
On Fri, 25 Apr 2008, Emi Lu wrote:

> Hi,
>
> Isn't this a bug about trim both.
>
>   select trim(both '<BR/>' from '<BR/>ROI Engineering Inc.');
>          btrim
> ---------------------
>   OI Engineering Inc.
> (1 row)
>
>
> "R" is missing? How?

Trim doesn't do what you think it does. The '<BR/>' in the above is not a
string to remove it is a list of characters to remove.  Thus, the R is
removed as it matches a character given.




Re: trim(both) problem?

From
"Fernando Hevia"
Date:
 

> -----Mensaje original-----
> De: pgsql-sql-owner@postgresql.org 
> [mailto:pgsql-sql-owner@postgresql.org] En nombre de Stephan Szabo
> Enviado el: Viernes, 25 de Abril de 2008 17:46
> Para: Emi Lu
> CC: pgsql-sql@postgresql.org
> Asunto: Re: [SQL] trim(both) problem?
> 
> On Fri, 25 Apr 2008, Emi Lu wrote:
> 
> > Hi,
> >
> > Isn't this a bug about trim both.
> >
> >   select trim(both '<BR/>' from '<BR/>ROI Engineering Inc.');
> >          btrim
> > ---------------------
> >   OI Engineering Inc.
> > (1 row)
> >
> >
> > "R" is missing? How?
> 
> Trim doesn't do what you think it does. The '<BR/>' in the 
> above is not a string to remove it is a list of characters to 
> remove.  Thus, the R is removed as it matches a character given.
> 

You could probably use instead:

select replace('<BR/>ROI Engineering Inc.', '<BR/>', '')




Re: trim(both) problem?

From
Tom Lane
Date:
"Fernando Hevia" <fhevia@ip-tel.com.ar> writes:
>> Trim doesn't do what you think it does. The '<BR/>' in the 
>> above is not a string to remove it is a list of characters to 
>> remove.  Thus, the R is removed as it matches a character given.

> You could probably use instead:

> select replace('<BR/>ROI Engineering Inc.', '<BR/>', '')

That would zap occurrences in the middle of the string, though.
regexp_replace would be better since it'd allow anchoring the
pattern, eg

select regexp_replace('<BR/>ROI Engineering Inc.', '^<BR/>', '');
select regexp_replace('ROI Engineering Inc.<BR/>', '<BR/>$', '');
        regards, tom lane


Re: trim(both) problem?

From
chester c young
Date:
--- Emi Lu <emilu@encs.concordia.ca> wrote:
> Isn't this a bug about trim both.
> 
>   select trim(both '<BR/>' from '<BR/>ROI Engineering Inc.');
>          btrim
> ---------------------
>   OI Engineering Inc.
> (1 row)
> 
> 
> "R" is missing? How?

you misread - '<BR/>' argument is a list of characters, _not_ a string.change 'ROI' to 'XOI' and you'll see.

     ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


Re: trim(both) problem?

From
Emi Lu
Date:
Thanks a lot for all help! I understand how trim work now.

>> You could probably use instead:
>> select replace('<BR/>ROI Engineering Inc.', '<BR/>', '')

> That would zap occurrences in the middle of the string, though.
> regexp_replace would be better since it'd allow anchoring the
> pattern, eg
> 
> select regexp_replace('<BR/>ROI Engineering Inc.', '^<BR/>', '');
> select regexp_replace('ROI Engineering Inc.<BR/>', '<BR/>$', '');

This is exactly I am looking for, but my version
PostgreSQL 8.0.15 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.2

does not support this func, and have to think about the other way to 
'trim' the ^<BR/> & <BR>$

Thank you again!