CoercionPathType pathtype;
Oid funcId;
- /*
- * A negative typmod is assumed to mean that no coercion is wanted. Also,
- * skip coercion if already done.
- */
- if (targetTypMod < 0 || targetTypMod == exprTypmod(node))
+ /* Skip coercion if already done */
+ if (targetTypMod == exprTypmod(node))
return node;
+ /* Suppress display of nested coercion steps */
+ if (hideInputCoercion)
+ hide_coercion_node(node);
+
pathtype = find_typmod_coercion_function(targetTypeId, &funcId);
if (pathtype != COERCION_PATH_NONE)
{
- /* Suppress display of nested coercion steps */
- if (hideInputCoercion)
- hide_coercion_node(node);
-
node = build_coercion_expression(node, pathtype, funcId,
targetTypeId, targetTypMod,
cformat, location,
isExplicit);
}
+ else
+ {
+ /*
+ * We don't need to perform any actual coercion step, but we should
+ * apply a RelabelType to ensure that the expression exposes the
+ * intended typmod.
+ */
+ RelabelType *rt;
+
+ rt = makeRelabelType((Expr *) node, targetTypeId, targetTypMod,
+ exprCollation(node),
+ cformat);
+ rt->location = location;
+ node = (Node *) rt;
+ }
return node;
}