mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Downgrade implicit casts to text to be assignment-only, except for the ones
from the other string-category types; this eliminates a lot of surprising interpretations that the parser could formerly make when there was no directly applicable operator. Create a general mechanism that supports casts to and from the standard string types (text,varchar,bpchar) for *every* datatype, by invoking the datatype's I/O functions. These new casts are assignment-only in the to-string direction, explicit-only in the other, and therefore should create no surprising behavior. Remove a bunch of thereby-obsoleted datatype-specific casting functions. The "general mechanism" is a new expression node type CoerceViaIO that can actually convert between *any* two datatypes if their external text representations are compatible. This is more general than needed for the immediate feature, but might be useful in plpgsql or other places in future. This commit does nothing about the issue that applying the concatenation operator || to non-text types will now fail, often with strange error messages due to misinterpreting the operator as array concatenation. Since it often (not always) worked before, we should either make it succeed or at least give a more user-friendly error; but details are still under debate. Peter Eisentraut and Tom Lane
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.217 2007/04/06 04:21:42 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.218 2007/06/05 21:31:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -145,6 +145,9 @@ static Datum ExecEvalFieldStore(FieldStoreState *fstate,
|
||||
static Datum ExecEvalRelabelType(GenericExprState *exprstate,
|
||||
ExprContext *econtext,
|
||||
bool *isNull, ExprDoneCond *isDone);
|
||||
static Datum ExecEvalCoerceViaIO(CoerceViaIOState *iostate,
|
||||
ExprContext *econtext,
|
||||
bool *isNull, ExprDoneCond *isDone);
|
||||
static Datum ExecEvalArrayCoerceExpr(ArrayCoerceExprState *astate,
|
||||
ExprContext *econtext,
|
||||
bool *isNull, ExprDoneCond *isDone);
|
||||
@ -3504,6 +3507,40 @@ ExecEvalRelabelType(GenericExprState *exprstate,
|
||||
return ExecEvalExpr(exprstate->arg, econtext, isNull, isDone);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* ExecEvalCoerceViaIO
|
||||
*
|
||||
* Evaluate a CoerceViaIO node.
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
static Datum
|
||||
ExecEvalCoerceViaIO(CoerceViaIOState *iostate,
|
||||
ExprContext *econtext,
|
||||
bool *isNull, ExprDoneCond *isDone)
|
||||
{
|
||||
Datum result;
|
||||
Datum inputval;
|
||||
char *string;
|
||||
|
||||
inputval = ExecEvalExpr(iostate->arg, econtext, isNull, isDone);
|
||||
|
||||
if (isDone && *isDone == ExprEndResult)
|
||||
return inputval; /* nothing to do */
|
||||
|
||||
if (*isNull)
|
||||
string = NULL; /* output functions are not called on nulls */
|
||||
else
|
||||
string = OutputFunctionCall(&iostate->outfunc, inputval);
|
||||
|
||||
result = InputFunctionCall(&iostate->infunc,
|
||||
string,
|
||||
iostate->intypioparam,
|
||||
-1);
|
||||
|
||||
/* The input function cannot change the null/not-null status */
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* ExecEvalArrayCoerceExpr
|
||||
*
|
||||
@ -3850,6 +3887,26 @@ ExecInitExpr(Expr *node, PlanState *parent)
|
||||
state = (ExprState *) gstate;
|
||||
}
|
||||
break;
|
||||
case T_CoerceViaIO:
|
||||
{
|
||||
CoerceViaIO *iocoerce = (CoerceViaIO *) node;
|
||||
CoerceViaIOState *iostate = makeNode(CoerceViaIOState);
|
||||
Oid iofunc;
|
||||
bool typisvarlena;
|
||||
|
||||
iostate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalCoerceViaIO;
|
||||
iostate->arg = ExecInitExpr(iocoerce->arg, parent);
|
||||
/* lookup the result type's input function */
|
||||
getTypeInputInfo(iocoerce->resulttype, &iofunc,
|
||||
&iostate->intypioparam);
|
||||
fmgr_info(iofunc, &iostate->infunc);
|
||||
/* lookup the input type's output function */
|
||||
getTypeOutputInfo(exprType((Node *) iocoerce->arg),
|
||||
&iofunc, &typisvarlena);
|
||||
fmgr_info(iofunc, &iostate->outfunc);
|
||||
state = (ExprState *) iostate;
|
||||
}
|
||||
break;
|
||||
case T_ArrayCoerceExpr:
|
||||
{
|
||||
ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
|
||||
|
Reference in New Issue
Block a user