Inconsistency: varchar is equivalent to varchar(255) and also not equivalent?

From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Inconsistency: varchar is equivalent to varchar(255) and also not equivalent?
Date: 2011-10-03 16:12:33
Message-ID: 4E89DEF1.6060103@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

here is the testcase:

create type mytype as (id integer, t varchar(255));
create table mytest (id serial, t1 varchar(255), t2 varchar(255));
create or replace function myfunc () returns setof mytype as $$
begin
return query select id, (t1 || t2)::varchar from mytest;
end;$$ language plpgsql;

Now the problem is:

select * from myfunc();
ERROR: structure of query does not match function result type
DETAIL: Returned type text does not match expected type character varying(255) in column 2.
CONTEXT: PL/pgSQL function "myfunc" line 2 at RETURN QUERY

But the types are said to be the same:

create cast (varchar as varchar(255)) without function;
ERROR: source data type and target data type are the same

create cast (varchar as varchar(255)) with inout;
ERROR: source data type and target data type are the same

This cast already exists:
create cast (varchar as varchar(255)) with function pg_catalog.varchar(varchar, integer,
boolean);
ERROR: cast from type character varying to type character varying already exists

I know, explicit cast to ::varchar(255) in the function solves this problem.
But I would like to know why isn't the type conversion from unlimited varchar
to varchar(255) invoked in the pl/pgsql function?

Thanks in advance,
Zoltán Böszörményi

--
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
http://www.postgresql.at/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message mgould 2011-10-03 16:13:44 Re: Why PGSQL has no developments in the .NET area?
Previous Message Andrew Sullivan 2011-10-03 15:24:51 Re: Searching for "bare" letters