diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index d3240f4b265..83ed74a22a4 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -540,6 +540,22 @@ coerce_type(ParseState *pstate, Node *node, r->location = location; return (Node *) r; } + + /* + * Callers assume that any input of type unknown is a literal, which can + * be coerced to anything (see can_coerce_type()), and literals were + * handled above. An unknown-typed expression that is not a literal, such + * as an explicit cast to unknown or a call to unknownin(), gets here, so + * report that as a user error rather than an internal one. + */ + if (inputTypeId == UNKNOWNOID) + ereport(ERROR, + (errcode(ERRCODE_CANNOT_COERCE), + errmsg("cannot cast type %s to %s", + format_type_be(inputTypeId), + format_type_be(targetTypeId)), + parser_coercion_errposition(pstate, location, node))); + /* If we get here, caller blew it */ elog(ERROR, "failed to find conversion function from %s to %s", format_type_be(inputTypeId), format_type_be(targetTypeId));