Move FOR PORTION OF volatile check into planner

This needs to be wary of the function volatility changing after we
check it.  We cannot enforce this when checking at parse time, so move
it later, into the planner.

Author: Paul A. Jungwirth <pj@illuminatedcomputing.com>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: jian he <jian.universality@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CA%2BrenyUte0_UJsJiDJQi82oaBsMJn%3Dcct0Wn%3DvOqXtuDn%3DYYJA%40mail.gmail.com
This commit is contained in:
Peter Eisentraut 2026-06-27 09:07:07 +02:00
parent dbaa4dc3c8
commit a272a58b94
2 changed files with 12 additions and 3 deletions

View file

@ -1081,6 +1081,18 @@ subquery_planner(PlannerGlobal *glob, Query *parse, char *plan_name,
/* exclRelTlist contains only Vars, so no preprocessing needed */
}
if (parse->forPortionOf)
{
parse->forPortionOf->targetRange =
preprocess_expression(root,
parse->forPortionOf->targetRange,
EXPRKIND_TARGET);
if (contain_volatile_functions(parse->forPortionOf->targetRange))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("FOR PORTION OF bounds cannot contain volatile functions")));
}
foreach(l, parse->mergeActionList)
{
MergeAction *action = (MergeAction *) lfirst(l);

View file

@ -1489,9 +1489,6 @@ transformForPortionOfClause(ParseState *pstate,
args,
InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL);
}
if (contain_volatile_functions_after_planning((Expr *) result->targetRange))
ereport(ERROR,
(errmsg("FOR PORTION OF bounds cannot contain volatile functions")));
/*
* Build overlapsExpr to use as an extra qual. This means we only hit rows