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

From Ken Hirsch
Subject Re: rtrim giving weird result
Date
Msg-id 009901c0ad01$25418f80$88873dd0@computer
Whole thread Raw
In response to rtrim giving weird result  ("G. Anthony Reina" <reina@nsi.edu>)
List pgsql-hackers
The second parameter to "rtrim" is interpreted as a set of characters and
rtrim:
"Returns string with final characters removed after the last character not
in set"

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.


----- Original Message -----
From: "G. Anthony Reina" <reina@nsi.edu>
To: "pgsql-hackers@postgreSQL.org" <pgsql-hackers@postgresql.org>
Sent: Wednesday, March 14, 2001 9:14 PM
Subject: [HACKERS] rtrim giving weird result


> I'm running Postgres 7.0.3 on a RedHat Linux 6.1. For some reason, rtrim
> is giving me an incorrect result:
>
> db01=# SELECT tablename FROM pg_tables WHERE tablename LIKE '%_opto' AND
>
> tablename NOT LIKE 'pg%'  ORDER BY tablename ASC ;
>     tablename
> -----------------
>  center_out_opto
>  circles_opto
>  ellipse_opto
>  ex_ellipse_opto
>  figure8_opto
>  ro_ellipse_opto
> (6 rows)
>
> Now I want to return the same thing only with the trailing '_opto'
> removed:
>
>
> db01=# SELECT rtrim(tablename, '_opto') FROM pg_tables WHERE tablename
> LIKE '%_opto' AND tablename NOT LIKE 'pg%'  ORDER BY tablename ASC ;
>    rtrim
> ------------
>  center_ou                                     <=======================
> NOTE: the trailing 't' is missing
>  circles
>  ellipse
>  ex_ellipse
>  figure8
>  ro_ellipse
> (6 rows)
>
> However, as you can see, the 'center_out' table is missing the last 't'.
> If I exclude the '_':
>
> db01=# SELECT rtrim(tablename, 'opto') FROM pg_tables WHERE tablename
> LIKE '%_opto' AND tablename NOT LIKE 'pg%'  ORDER BY tablename ASC ;
>     rtrim
> -------------
>  center_out_
> <=======================   't' shows up again
>  circles_
>  ellipse_
>  ex_ellipse_
>  figure8_
>  ro_ellipse_
> (6 rows)
>
> The 't' is back.
>
> Is there something that I'm doing wrong with my query here?
>
> Thanks.
> -Tony
>
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>



pgsql-hackers by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Union on view and..
Next
From: Tim Allen
Date:
Subject: Database corruption in 7.0.3