Casts question

From: Shachar Shemesh <psql(at)shemesh(dot)biz>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Casts question
Date: 2004-06-17 16:58:39
Message-ID: 40D1CDBF.2060300@shemesh.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

I have defined a datatype called "varcharci", shamelessly yanking the
input, output, recv and send functions from varchar. This means (as far
as I understand things) that this type is binary compatible with varchar.

As such, I used the following two lines:
create cast ( varcharci AS varchar ) WITHOUT FUNCTION AS IMPLICIT;
create cast ( varchar AS varcharci ) WITHOUT FUNCTION AS ASSIGNMENT;

I defined two tables. Both have a column called "name". One is a
varchar, and the other is a varcharci. When I try to do the following
select, I get an error:
test=# select test2.id as "id-1", test3.id as "id-2", test2.name from
test2 inner join test3 on test2.name=test3.name;
ERROR: operator does not exist: character varying = varcharci
HINT: No operator matches the given name and argument type(s). You may
need to add explicit type casts.

When I add an explicit cast, everything works:
sun=# select test2.id as "id-1", test3.id as "id-2", test2.name from
test2 inner join test3 on test2.name=cast(test3.name as varchar);
results go here

Why is that? Being as it is that no operator = is defined for varcharci,
and that the cast from varchar to varcharci is "as assignment" anyways,
shouldn't postgres be able to do the cast implicitly?

Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting ltd.
http://www.lingnu.com/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message markw 2004-06-17 17:00:28 Re: Status in 7.5 patches
Previous Message Andrew Sullivan 2004-06-17 16:51:03 Re: signal 11 on AIX: 7.4.2