]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Move FOR PORTION OF volatile check into planner
authorPeter Eisentraut <peter@eisentraut.org>
Sat, 27 Jun 2026 07:07:07 +0000 (09:07 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sat, 27 Jun 2026 11:51:11 +0000 (13:51 +0200)
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

src/backend/optimizer/plan/planner.c
src/backend/parser/analyze.c

index f4689e7c9f8bfc7c1a8e628ad8d91c602c3b1473..846bd7c1fbe6a15247e11742325b975e68b546d4 100644 (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);
index 93fa66ae57ce706b909b6adcc841dafb57a125b4..76758adefb6f18b2539d249acd8b256c550d9153 100644 (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