Re: string cast/compare broken?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Zeugswetter Andreas SB SD" <ZeugswetterA(at)spardat(dot)at>
Cc: "Hannu Krosing" <hannu(at)tm(dot)ee>, "Scott Royston" <scroyston(at)mac(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: string cast/compare broken?
Date: 2002-07-12 13:16:58
Message-ID: 9036.1026479818@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Zeugswetter Andreas SB SD" <ZeugswetterA(at)spardat(dot)at> writes:
>> If the conversion where varchar(5) --> char(5) then
>> they would compare equal.

> I am not sure, since, if the varchar stored 'S ' then the comparison
> to a char 'S' should probably still fail,

There is no comparison of varchar to char:

regression=# select 'z'::char = 'z'::varchar;
ERROR: Unable to identify an operator '=' for types 'character' and 'character varying'
You will have to retype this query using an explicit cast
regression=#

I consider this a feature, not a bug, since it's quite unclear which
semantics ought to be used.

The cases Scott originally posted all involved various forms of
coercion to force both sides to be the same type; I'm not sure
that he quite understood why he had to do that, but perhaps it's now
becoming clear.

I wonder whether it would be a good idea to stop considering char
as binary-compatible to varchar and text. Instead we could set
things up so that there is a coercion function involved, namely
rtrim(). But that would probably make us diverge even further
from the spec.

Has anyone studied how other DBMSs handle CHAR vs VARCHAR? Judging
from the number of questions we get on this point, I have to wonder
if we are not out of step with the way other systems do it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zeugswetter Andreas SB SD 2002-07-12 13:48:59 Re: string cast/compare broken?
Previous Message Rod Taylor 2002-07-12 12:51:50 Re: Bug of PL/pgSQL parser