Re: rtrim giving weird result

Поиск
Список
Период
Сортировка
От Ross J. Reedstrom
Тема Re: rtrim giving weird result
Дата
Msg-id 20010315115337.A4454@rice.edu
обсуждение исходный текст
Ответ на Re: rtrim giving weird result  ("G. Anthony Reina" <reina@nsi.edu>)
Ответы Re: rtrim giving weird result  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Allowing WAL fsync to be done via O_SYNC
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: Allowing WAL fsync to be done via O_SYNC