Обсуждение: Char = varchar

Поиск
Список
Период
Сортировка

Char = varchar

От
"Glen Parker"
Дата:
Hi all,

Didn't see a reference to this in the archives, so here goes.
In pg 7.2.1, comparing char to varchar appears broken.  Can't believe
there isnt more chatter about this on the list.  Anyhow, try the
following:

  Create table test (field1 char(10), field2 varchar(10));
  Select count(*) from test where field1 = field2;

You get:

  ERROR:  Unable to identify an operator '=' for types 'character' and
'character varying'
    You will have to retype this query using an explicit cast

Not sure what I'm asking for here...  I know casting will fix it, I know
changing my schema will work.  Would creating an operator be a
reasonable workaround perhaps?

Tia
Glen Parker
glenebob@nwlink.com


Re: Char = varchar

От
Tom Lane
Дата:
"Glen Parker" <glenebob@nwlink.com> writes:
>   ERROR:  Unable to identify an operator '=' for types 'character' and
> 'character varying'

The reason it's unhappy is that it has no reasonable way to make a
choice between using char and varchar comparison (which are not the
same; the former is insensitive to trailing blanks).  You need a
cast to tell it what to do.

            regards, tom lane