pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
trim(both) problem?
7+ messages / 5 participants
[nested] [flat]

* trim(both) problem?
@ 2008-04-25 20:33  Emi Lu <emilu@encs.concordia.ca>
  0 siblings, 3 replies; 7+ messages in thread

From: Emi Lu @ 2008-04-25 20:33 UTC (permalink / raw)
  To: pgsql-sql

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, compiled by GCC gcc (GCC) 3.3.2

Thank you!









^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: trim(both) problem?
@ 2008-04-25 20:44  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Emi Lu <emilu@encs.concordia.ca>
  2 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2008-04-25 20:44 UTC (permalink / raw)
  To: emilu@encs.concordia.ca; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: trim(both) problem?
@ 2008-04-25 20:45  Stephan Szabo <sszabo@megazone.bigpanda.com>
  parent: Emi Lu <emilu@encs.concordia.ca>
  2 siblings, 1 reply; 7+ messages in thread

From: Stephan Szabo @ 2008-04-25 20:45 UTC (permalink / raw)
  To: Emi Lu <emilu@encs.concordia.ca>; +Cc: pgsql-sql

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.





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: trim(both) problem?
@ 2008-04-25 21:03  Fernando Hevia <fhevia@ip-tel.com.ar>
  parent: Stephan Szabo <sszabo@megazone.bigpanda.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Fernando Hevia @ 2008-04-25 21:03 UTC (permalink / raw)
  To: 'Emi Lu' <emilu@encs.concordia.ca>; +Cc: pgsql-sql

 

> -----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/>', '')





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: trim(both) problem?
@ 2008-04-25 21:26  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Fernando Hevia <fhevia@ip-tel.com.ar>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2008-04-25 21:26 UTC (permalink / raw)
  To: Fernando Hevia <fhevia@ip-tel.com.ar>; +Cc: 'Emi Lu' <emilu@encs.concordia.ca>; pgsql-sql

"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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: trim(both) problem?
@ 2008-04-25 21:48  chester c young <chestercyoung@yahoo.com>
  parent: Emi Lu <emilu@encs.concordia.ca>
  2 siblings, 0 replies; 7+ messages in thread

From: chester c young @ 2008-04-25 21:48 UTC (permalink / raw)
  To: emilu@encs.concordia.ca; +Cc: pgsql-sql

--- 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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: trim(both) problem?
@ 2008-04-28 13:19  Emi Lu <emilu@encs.concordia.ca>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Emi Lu @ 2008-04-28 13:19 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Fernando Hevia <fhevia@ip-tel.com.ar>; pgsql-sql

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!



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2008-04-28 13:19 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-04-25 20:33 trim(both) problem? Emi Lu <emilu@encs.concordia.ca>
2008-04-25 20:44 ` Tom Lane <tgl@sss.pgh.pa.us>
2008-04-25 20:45 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2008-04-25 21:03   ` Fernando Hevia <fhevia@ip-tel.com.ar>
2008-04-25 21:26     ` Tom Lane <tgl@sss.pgh.pa.us>
2008-04-28 13:19       ` Emi Lu <emilu@encs.concordia.ca>
2008-04-25 21:48 ` chester c young <chestercyoung@yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox