
> 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.

Well, I already gave the Informix example, that compares them as equal.
(they obviously coerce varchar to char)

In nearly all cases I have seen so far the different handling of trailing
blanks is not wanted. In most of these varchar is simply used instead of char to 
save disk space.

In Informix ESQL/C there is a host variable type CSTRINGTYPE that automatically 
rtrims columns of char type upon select.

Imho the advantages of an automatic coercion would outweigh the few corner cases
where the behavior would not be intuitive to everybody.

Andreas

Fri, 12 Jul 2002 15:48:59 +0200
"Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at>
Re: string cast/compare broken? 
There is no comparison of varchar to char in Oracle too.
Scott provided cast cases are some unique features in psql, 
each database MAY handle those casting differently.

In good design/application, char should be replaced by
varchar type unless you know the exact bytes. It would be
not bad idea to get rid of char gradually in the future
to avoid such inconsistency 
between databases, that's just my view.

johnl

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Zeugswetter
> Andreas SB SD
> Sent: Friday, July 12, 2002 8:49 AM
> To: Tom Lane
> Cc: Hannu Krosing; Scott Royston; pgsql-hackers@postgresql.org
> Subject: Re: [HACKERS] string cast/compare broken? 
> 
> 
> 
> > 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.
> 
> Well, I already gave the Informix example, that compares them as equal.
> (they obviously coerce varchar to char)
> 
> In nearly all cases I have seen so far the different handling of trailing
> blanks is not wanted. In most of these varchar is simply used 
> instead of char to 
> save disk space.
> 
> In Informix ESQL/C there is a host variable type CSTRINGTYPE that 
> automatically 
> rtrims columns of char type upon select.
> 
> Imho the advantages of an automatic coercion would outweigh the 
> few corner cases
> where the behavior would not be intuitive to everybody.
> 
> Andreas
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

Fri, 12 Jul 2002 09:24:03 -0500
"John Liu" <johnl@synthesys.com>
Re: string cast/compare broken? 
On Fri, Jul 12, 2002 at 03:48:59PM +0200, Zeugswetter Andreas SB SD wrote:
> Imho the advantages of an automatic coercion would outweigh the few
> corner cases where the behavior would not be intuitive to
> everybody.

How then would one get the correct behaviour from char()?

A

-- 
----
Andrew Sullivan                               87 Mowat Avenue 
Liberty RMS                           Toronto, Ontario Canada
<andrew@libertyrms.info>                              M6K 3E3
                                         +1 416 646 3304 x110


Fri, 12 Jul 2002 11:28:20 -0400
Andrew Sullivan <andrew@libertyrms.info>
Re: string cast/compare broken?