Re: ERROR: failed to find conversion function from unknown to text

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ERROR: failed to find conversion function from unknown to text
Date: 2026-04-22 06:33:01
Message-ID: CACJufxF7iSeRF2+bprERSwBe5zShVch1EJK-KcxQCcLT-UHBbg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 29, 2026 at 11:53 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> To make it an error, meaning it's not possible to coerce to the unknown type.
> We can do it in the function find_coercion_pathway, just
> after the ``if (sourceTypeId == targetTypeId)`` check:
>
> if (targetTypeId == UNKNOWNOID)
> return COERCION_PATH_NONE;
>
> it's also doable in the function can_coerce_type,
> right after the ``if (inputTypeId == UNKNOWNOID)``:
>
> if (targetTypeId == UNKNOWNOID)
> return false;

I choose to disallow UNKNOWN target types in find_coercion_pathway.

do $$ declare a int;
begin a := '1'::text::unknown;
end$$;

This DO statement does not cause any error in the HEAD, because of
function find_coercion_pathway:
```
/*
* When parsing PL/pgSQL assignments, allow an I/O cast to be used
* whenever no normal coercion is available.
*/
if (result == COERCION_PATH_NONE &&
ccontext == COERCION_PLPGSQL)
result = COERCION_PATH_COERCEVIAIO;
```

but will result error with the attached V2:
ERROR: cannot cast type text to unknown

--
jian
https://www.enterprisedb.com/

Attachment Content-Type Size
v2-0001-Disallow-UNKNOWN-target-types.patch text/x-patch 2.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Yuchen Li 2026-04-22 06:34:46 Re: Cleanup shadows variable warnings, round 1
Previous Message Peter Smith 2026-04-22 06:32:25 Re: Cleanup shadows variable warnings, round 1