Re: rtrim giving weird result

From: "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
To: "G(dot) Anthony Reina" <reina(at)nsi(dot)edu>
Cc: "pgsql-hackers(at)postgreSQL(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: rtrim giving weird result
Date: 2001-03-15 17:53:37
Message-ID: 20010315115337.A4454@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-03-15 18:15:18 Re: Allowing WAL fsync to be done via O_SYNC
Previous Message Tom Lane 2001-03-15 17:48:14 Re: Allowing WAL fsync to be done via O_SYNC