if (type != atp->atttypid)
{
- /*
- * Though these types are binary compatible, bpchar has a fixed
- * length on the disk, requiring non-bpchar types to be padded
- * before storage in the default table. bjm 1999/05/18
- */
- if (1==0 && atp->atttypid == BPCHAROID &&
- (type == TEXTOID || type == BPCHAROID || type == UNKNOWNOID))
- {
-
- FuncCall *n = makeNode(FuncCall);
-
- n->funcname = typeidTypeName(atp->atttypid);
- n->args = lcons((Node *)expr, NIL);
- expr = transformExpr(NULL, (Node *) n, EXPR_COLUMN_FIRST);
-
- }
- else if (IS_BINARY_COMPATIBLE(type, atp->atttypid))
+ if (IS_BINARY_COMPATIBLE(type, atp->atttypid))
; /* use without change */
else if (can_coerce_type(1, &(type), &(atp->atttypid)))
- expr = coerce_type(NULL, (Node *)expr, type, atp->atttypid);
+ expr = coerce_type(NULL, (Node *)expr, type, atp->atttypid,
+ atp->atttypmod);
else if (IsA(expr, Const))
{
if (*cast != 0)
* Convert a function argument to a different type.
*/
Node *
-coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId)
+coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
+ int32 atttypmod)
{
Node *result = NULL;
Oid infunc;
con->consttype = targetTypeId;
con->constlen = typeLen(typeidType(targetTypeId));
- /* use "-1" for varchar() type */
+ /*
+ * Use "-1" for varchar() type.
+ * For char(), we need to pad out the type with the proper
+ * number of spaces. This was a major problem for
+ * DEFAULT string constants to char() types.
+ */
con->constvalue = (Datum) fmgr(infunc,
val,
typeidTypElem(targetTypeId),
- -1);
+ (targetTypeId != BPCHAROID) ? -1 : atttypmod);
con->constisnull = false;
con->constbyval = typeByVal(typeidType(targetTypeId));
con->constisset = false;
result = node;
return result;
-} /* coerce_type() */
+}
/* can_coerce_type()
}
return true;
-} /* can_coerce_type() */
+}
/* TypeCategory()
}
else if (can_coerce_type(1, &c->casetype, &ptype))
{
- c->defresult = coerce_type(pstate, c->defresult, c->casetype, ptype);
+ c->defresult = coerce_type(pstate, c->defresult,
+ c->casetype, ptype, -1);
c->casetype = ptype;
}
else
{
if (can_coerce_type(1, &wtype, &ptype))
{
- w->result = coerce_type(pstate, w->result, wtype, ptype);
+ w->result = coerce_type(pstate, w->result, wtype,
+ ptype, -1);
}
else
{
}
else
{
-
/*
* Parsing aggregates.
*/
int ncandidates;
CandidateList candidates;
-
/*
* the aggregate COUNT is a special case, ignore its base
* type. Treat it as zero
type = agg_select_candidate(basetype, candidates);
if (OidIsValid(type))
{
- lfirst(fargs) = coerce_type(pstate, lfirst(fargs), basetype, type);
+ lfirst(fargs) = coerce_type(pstate, lfirst(fargs),
+ basetype, type, -1);
basetype = type;
return (Node *) ParseAgg(pstate, funcname, basetype,
lfirst(current_fargs) = coerce_type(pstate,
lfirst(current_fargs),
input_typeids[i],
- function_typeids[i]);
+ function_typeids[i], -1);
}
}
}
/* must coerce? */
if (true_typeId != orig_typeId)
- {
- result = coerce_type(NULL, tree, orig_typeId, true_typeId);
- }
+ result = coerce_type(NULL, tree, orig_typeId, true_typeId, -1);
}
/* otherwise, this is a NULL value */
else
{
if (can_coerce_type(1, &attrtype_id, &attrtype_target))
{
- Node *expr = coerce_type(pstate, expr, attrtype_id, attrtype_target);
+ Node *expr = coerce_type(pstate, expr, attrtype_id,
+ attrtype_target,
+ get_atttypmod(pstate->p_target_relation->rd_id, resdomno_target));
elog(ERROR, "Type %s(%d) can be coerced to match target column %s(%d)",
colname, get_atttypmod(rte->relid, resdomno_id),
{
if (can_coerce_type(1, &attrtype_id, &attrtype_target))
{
- expr = coerce_type(pstate, node, attrtype_id, attrtype_target);
+ expr = coerce_type(pstate, node, attrtype_id,
+ attrtype_target,
+ get_atttypmod(pstate->p_target_relation->rd_id, resdomno_target));
expr = transformExpr(pstate, expr, EXPR_COLUMN_FIRST);
tent = MakeTargetEntryExpr(pstate, *resname, expr, false, false);
expr = tent->expr;
{
if (can_coerce_type(1, &type_id, &attrtype))
{
- expr = coerce_type(pstate, expr, type_id, attrtype);
+ expr = coerce_type(pstate, expr, type_id, attrtype, -1);
}
#ifndef DISABLE_STRING_HACKS
{
}
else if (can_coerce_type(1, &type_id, &text_id))
- expr = coerce_type(pstate, expr, type_id, text_id);
+ expr = coerce_type(pstate, expr, type_id, text_id, -1);
else
expr = NULL;
}
extern CATEGORY TypeCategory(Oid type);
extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
-extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId);
+extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
+ Oid targetTypeId, int32 atttypmod);
#endif /* PARSE_COERCE_H */