Re: whitespaces and upper()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Flavio Casadei D(dot) C(dot)" <f(dot)casadeidellachiesa(at)comune(dot)prato(dot)it>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: whitespaces and upper()
Date: 2004-06-07 13:41:53
Message-ID: 2494.1086615713@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Flavio Casadei D. C." <f(dot)casadeidellachiesa(at)comune(dot)prato(dot)it> writes:
> create table foo (
> id integer not null primary key,
> name char(6) not null,
> value varchar(255)
> );
> insert into foo values (1,'FLAVIO','hi!');
> insert into foo values (2,'FLA ' ,'hi!');
> insert into foo values (3,' ','hi!');
> insert into foo values (4,' d ','hi!');
> test=> SELECT * from foo ;
> id | name | value
> ----+--------+-------
> 1 | FLAVIO | hi!
> 2 | FLA | hi!
> 3 | | hi!
> 4 | d | hi!
> (4 righe)

> test=> SELECT * from foo where upper(name) like '% ';
> id | name | value
> ----+------+-------
> (0 righe)

This is because upper() takes a text argument, and as of 7.4 char(N) to
text conversion discards trailing spaces. I believe this behavior is
correct on balance: if you think that trailing spaces are significant
data, you ought to be storing the column as varchar or text, not char.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander S. 2004-06-07 18:11:33 bug in 7.4.2, concern unicode and russian content of db
Previous Message Flavio Casadei D. C. 2004-06-07 06:22:07 whitespaces and upper()