Copy a Param's location field when replacing it with a Const.

This allows Param substitution to produce just the same result
as writing a constant value literally would have done.  While
it hardly matters so far as the current core code is concerned,
extensions might take more interest in node location fields.

Julien Rouhaud

Discussion: https://postgr.es/m/20170311220932.GJ15188@nol.local
This commit is contained in:
Tom Lane 2021-07-14 14:15:12 -04:00
parent c203dcddf9
commit be850f1822

View File

@ -2329,6 +2329,7 @@ eval_const_expressions_mutator(Node *node,
int16 typLen;
bool typByVal;
Datum pval;
Const *con;
get_typlenbyval(param->paramtype,
&typLen, &typByVal);
@ -2336,13 +2337,15 @@ eval_const_expressions_mutator(Node *node,
pval = prm->value;
else
pval = datumCopy(prm->value, typByVal, typLen);
return (Node *) makeConst(param->paramtype,
param->paramtypmod,
param->paramcollid,
(int) typLen,
pval,
prm->isnull,
typByVal);
con = makeConst(param->paramtype,
param->paramtypmod,
param->paramcollid,
(int) typLen,
pval,
prm->isnull,
typByVal);
con->location = param->location;
return (Node *) con;
}
}
}