diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index 2ffe470..08ca348 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -1,3 +1,4 @@ + /*------------------------------------------------------------------------- * * parse_coerce.c @@ -94,6 +95,7 @@ coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, * *must* know that to avoid possibly calling hide_coercion_node on * something that wasn't generated by coerce_type. Note that if there are * multiple stacked CollateExprs, we just discard all but the topmost. + * Also, if the target type isn't collatable, we discard the CollateExpr. */ origexpr = expr; while (expr && IsA(expr, CollateExpr)) @@ -113,7 +115,7 @@ coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, ccontext, cformat, location, (result != expr && !IsA(result, Const))); - if (expr != origexpr) + if (expr != origexpr && type_is_collatable(targettype)) { /* Reinstall top CollateExpr */ CollateExpr *coll = (CollateExpr *) origexpr; @@ -381,6 +383,7 @@ coerce_type(ParseState *pstate, Node *node, if (result) return result; } + if (IsA(node, CollateExpr)) { /* @@ -392,6 +395,13 @@ coerce_type(ParseState *pstate, Node *node, CollateExpr *coll = (CollateExpr *) node; CollateExpr *newcoll = makeNode(CollateExpr); + + if (!type_is_collatable(targetTypeId)) { + return coerce_type(pstate, (Node *) coll->arg, + inputTypeId, targetTypeId, targetTypeMod, + ccontext, cformat, location); + } + newcoll->arg = (Expr *) coerce_type(pstate, (Node *) coll->arg, inputTypeId, targetTypeId, targetTypeMod, @@ -2890,3 +2900,4 @@ typeIsOfTypedTable(Oid reltypeId, Oid reloftypeId) return result; } + -- 2.11.0