Re: rtrim giving weird result - Mailing list pgsql-hackers

From Ross J. Reedstrom
Subject Re: rtrim giving weird result
Date
Msg-id 20010315115337.A4454@rice.edu
Whole thread Raw
In response to Re: rtrim giving weird result  ("G. Anthony Reina" <reina@nsi.edu>)
Responses Re: rtrim giving weird result  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Thu, Mar 15, 2001 at 09:34:04AM -0800, G. Anthony Reina wrote:
> Ken Hirsch wrote:
> 
> > So rtrim("center_out_opto", "_opto") returns
> >     "center_ou"
> > because "u" is not in the set {o, p, t, _} but all the characters after it
> > are.
> > rtrim("center_out_opto", "pot_") will produce the same thing.
> >

Modulo the correct quoting conventions for strings, of course.

> 
> That seems like an odd definition (although as Tom points out, it is
> consistent with Oracle).

Yup, I got bit by it, trying to remove 'The ' from the front of a set of
words, in order to get an approximation of 'library sort'.

> 
> Is there a way to just remove the "_opto" from the end of the string?

If you have exactly one known string to (optionally) remove, this works
(and even works if the string is missing. Watch out for the early
occurance of substring problem, though!):

test=# select substr('center_out_opto',1,(strpos('center_out_opto','_opto')-1));   substr   
------------center_out
(1 row)

test=#  select substr('center_out_opto',1,(strpos('center_out_opto','foo')-1));    substr      
-----------------center_out_opto
(1 row)

test=# 

Ross


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Allowing WAL fsync to be done via O_SYNC
Next
From: Peter Eisentraut
Date:
Subject: Re: Allowing WAL fsync to be done via O_SYNC