Failure to coerce unknown type to specific type

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Failure to coerce unknown type to specific type
Date: 2015-04-09 01:21:44
Message-ID: CAMp0ubdECGUJWpQKyUM36PxQWoKe0VfTbHGHgn+w2H_5q1Nmow@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Original report and patch by Karl Schnaitter.

create table a(u) as select '1';
create table b(i int);
insert into b select u from a;
ERROR: failed to find conversion function from unknown to integer

SELECT a=b FROM (SELECT ''::text, ' ') x(a,b);
ERROR: failed to find conversion function from unknown to text

The strange thing about these cases are that can_coerce_type returns
true, but coerce_type fails.

This can be fixed by a small change (attached) to find_coercion_pathway to add:

else if (sourceTypeId == UNKNOWNOID)
result = COERCION_PATH_COERCEVIAIO;

I don't see any big problem with doing this, because we've already
done the type inference; it's just a question of whether we succeed or
fail when we try to apply it. I don't see any reason to fail a cast
from unknown to something else.

However, this still doesn't fix a more complex case like:

create table tt(x text primary key);
create table ut(x unknown, foreign key(x) references tt);
insert into tt values('');
insert into ut values('');
update ut set x = x;

Regards,
Jeff Davis

Attachment Content-Type Size
unknown_coerce.patch text/x-diff 2.6 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2015-04-09 01:31:52 Re: Failure to coerce unknown type to specific type
Previous Message Jeff Janes 2015-04-08 21:25:14 Re: BUG #13002: VACUUM to prevent wraparound blocks TRUNCATE

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-04-09 01:31:52 Re: Failure to coerce unknown type to specific type
Previous Message Michael Paquier 2015-04-09 00:59:16 Re: "rejected" vs "returned with feedback" in new CF app