Thread: [BUGS] BUG #14478: Right Trim trims too much?

[BUGS] BUG #14478: Right Trim trims too much?

From
nte@mustinformatique.fr
Date:
The following bug has been logged on the website:

Bug reference:      14478
Logged by:          Nathanael TERRIEN
Email address:      nte@mustinformatique.fr
PostgreSQL version: 9.6.1
Operating system:   Windows
Description:

Not sure if a bug or if I'm missing something but this query produces weird
results with TRIM and TRIM:
SELECT DISTINCT TRIM(TRAILING FROM 'cnam_lpp_histo_io','_io') AS "A"
    ,RTRIM('cnam_lpp_histo_io','_io') AS "B"
    ,REPLACE('cnam_lpp_histo_io','_io','') AS "C"
    ,REGEXP_REPLACE('cnam_lpp_histo_io','_io$','') AS "D";
Results A and B seems wrong to me (C and D are OK):
A=cnam_lpp_hist
B=cnam_lpp_hist
C=cnam_lpp_histo
D=cnam_lpp_histo


--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Re: [BUGS] BUG #14478: Right Trim trims too much?

From
Terje Elde
Date:


On 26 Dec 2016, at 10:36, nte@mustinformatique.fr wrote:

Not sure if a bug or if I'm missing something but this query produces weird
results with TRIM and TRIM:
SELECT DISTINCT TRIM(TRAILING FROM 'cnam_lpp_histo_io','_io')

The devil is in the details. Trim won't remove the string "_io", it'll trim off the characters "_", "i" and "o". And with that logic, the "o" at the end of "histo" is correctly removed as well.

IOW, works as intended and advertised.

Doc here:

Terje

Re: [BUGS] BUG #14478: Right Trim trims too much?

From
Nathanael Terrien
Date:

Ok, I misunderstood the documentation. The way it works is logical.

Thank you.

 

 

De : Terje Elde [mailto:terje@elde.net]
Envoyé : lundi 26 décembre 2016 15:52
À : Nathanael Terrien <nte@mustinformatique.fr>
Cc : pgsql-bugs@postgresql.org
Objet : Re: [BUGS] BUG #14478: Right Trim trims too much?

 

 


On 26 Dec 2016, at 10:36, nte@mustinformatique.fr wrote:

Not sure if a bug or if I'm missing something but this query produces weird
results with TRIM and TRIM:
SELECT DISTINCT TRIM(TRAILING FROM 'cnam_lpp_histo_io','_io')

 

The devil is in the details. Trim won't remove the string "_io", it'll trim off the characters "_", "i" and "o". And with that logic, the "o" at the end of "histo" is correctly removed as well.

 

IOW, works as intended and advertised.

 

Doc here:

 

Terje

Re: [BUGS] BUG #14478: Right Trim trims too much?

From
Tom Lane
Date:
Nathanael Terrien <nte@mustinformatique.fr> writes:
> Ok, I misunderstood the documentation. The way it works is logical.

Actually, we changed the docs about the *trim functions recently because
somebody else made the same mistake.  The examples, in particular,
weren't chosen in a way that would make it clear that the characters-
to-trim are sets not strings.  You can see the new wording at

https://www.postgresql.org/docs/devel/static/functions-string.html

That will propagate into the released-version pages at the next
minor updates (scheduled for early Feb).

            regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Re: [BUGS] BUG #14478: Right Trim trims too much?

From
Nathanael Terrien
Date:
The new wording is clearer. Thanks.

-----Message d'origine-----
De : Tom Lane [mailto:tgl@sss.pgh.pa.us]
Envoyé : lundi 26 décembre 2016 17:36
À : Nathanael Terrien <nte@mustinformatique.fr>
Cc : 'Terje Elde' <terje@elde.net>; pgsql-bugs@postgresql.org
Objet : Re: [BUGS] BUG #14478: Right Trim trims too much?

Nathanael Terrien <nte@mustinformatique.fr> writes:
> Ok, I misunderstood the documentation. The way it works is logical.

Actually, we changed the docs about the *trim functions recently because somebody else made the same mistake.  The
examples,in particular, weren't chosen in a way that would make it clear that the characters- to-trim are sets not
strings. You can see the new wording at 

https://www.postgresql.org/docs/devel/static/functions-string.html

That will propagate into the released-version pages at the next minor updates (scheduled for early Feb).

            regards, tom lane


--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs