Re: bug/feature with upper function?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Vincent Stoessel <vincent(at)xaymaca(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: bug/feature with upper function?
Date: 2002-03-20 18:54:34
Message-ID: 20020320104555.W47650-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 20 Mar 2002, Vincent Stoessel wrote:

> I am having a serious problem matching text using the upper() function
> in postgres 7.2 (from developer rpms) on Redhat 7.2
>
> FEC=# SELECT * from upp_test where uname = 'KAT' ;
> uname
> ----------------------
> KAT
> KAT
> KAT
> KAT
> KAT
> (5 rows)
>
> db=# SELECT * from upp_test where upper(uname) = 'KAT' ;
> uname
> -------
> (0 rows)
>
> The reason I am worried about this is that I have a mix of upper and
> lower case words in the real world coumn and I have not been getting
> complete matches. Is this a bug?

You're getting a type conversion with upper (IIRC it's upper(text) returns
text) which is changing the behavior relating to the padding spaces.
It's going to think the upper is 'KAT ' (I think I counted
out the right number of spaces).

In general it's often easiest to make the column varchar rather than char
unless you really are using the padding behavior, but you could possible
get away with an additional upper function:

create function upper(character) returns character as 'select upper(CAST(
$1 as text));' language 'sql';

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bradley Brown 2002-03-20 18:55:59 dbase restore
Previous Message Richard Huxton 2002-03-20 18:48:08 Re: bug/feature with upper function?