BUG #14478: Right Trim trims too much?

Started by Nathanael Terrienover 9 years ago5 messagesbugs
Jump to latest
#1Nathanael Terrien
nte@mustinformatique.fr

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

#2Terje Elde
terje@elde.net
In reply to: Nathanael Terrien (#1)
Re: 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:
https://www.postgresql.org/docs/current/static/functions-string.html

Terje

#3Nathanael Terrien
nte@mustinformatique.fr
In reply to: Terje Elde (#2)
Re: BUG #14478: Right Trim trims too much?

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<mailto: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:
https://www.postgresql.org/docs/current/static/functions-string.html

Terje

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Nathanael Terrien (#3)
Re: 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

#5Nathanael Terrien
nte@mustinformatique.fr
In reply to: Tom Lane (#4)
Re: BUG #14478: Right Trim trims too much?

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