Equal test on strings doesn't ignore trailing spaces if the function 'lower' is applied

Started by Alain TESIOover 26 years ago2 messagesbugs
Jump to latest
#1Alain TESIO
tesio@easynet.fr

I have to apply rtrim explicitely if the string to
compare has been converted to lowercase :

dip=> create table testlower ( t char(50) );
CREATE
dip=> insert into testlower values ( 'Aa' );
INSERT 1257077 1
dip=> select t from testlower where t='Aa';
t
--------------------------------------------------
Aa
(1 row)
dip=> select t from testlower where lower(t)='aa';
t
-
(0 rows)
dip=> select t from testlower where rtrim(lower(t))='aa';
t
--------------------------------------------------
Aa
(1 row)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alain TESIO (#1)
Re: [BUGS] Equal test on strings doesn't ignore trailing spaces if the function 'lower' is applied

"Alain TESIO" <tesio@easynet.fr> writes:

I have to apply rtrim explicitely if the string to
compare has been converted to lowercase :

lower() is a text function, not a fixed-length-char function,
so the result of lower() is assumed to have significant trailing
blanks. It's not clear to me that the behavior you're complaining
about is a bug.

I'd suggest using varchar or text if you are dealing with strings
that are actually variable-length.

regards, tom lane