Re: SQL:2011 Application Time Update & Delete
Paul A Jungwirth <pj@illuminatedcomputing.com>
From: Paul A Jungwirth <pj@illuminatedcomputing.com>
To: jian he <jian.universality@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>, Chao Li <li.evan.chao@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-15T21:59:21Z
Lists: pgsql-hackers
On Mon, Apr 6, 2026 at 9:04 PM jian he <jian.universality@gmail.com> wrote:
>
> As you can see, ExecGetAllUpdatedCols does not account for the valid_at column,
> even though it is actively being updated. ExecGetAllUpdatedCols is being used
> serval places, IMHO, we need to add some comments on
> ExecGetAllUpdatedCols explaining
> this behavior and maybe add some regression tests.
>
> I'm not sure if it's safe for ExecGetAllUpdatedCols to ignore the FOR
> PORTION OF column.
The other threads have found a couple problems with that now. I wonder
if we should have ExecGetExtraUpdatedCols add the application-time
attno to the returned bitmapset? Or even add it to updatedCols in
analysis and then ignore it for permission checking. That seems more
robust than finding all the places we need to add it, except
updatedCols is in a struct called RTEPermissionInfo. Best of all I
think would be to add a new bitmapset somewhere else and not use
permissions infrastructure for GENERATED columns, UPDATE OF triggers,
skipping CHECK constraints, etc. But is it too late in the cycle to
make a change like that?
In the short term, what about just doing this?:
@@ -1449,6 +1449,7 @@ ExecGetAllUpdatedCols(ResultRelInfo *relinfo,
EState *estate)
oldcxt = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
ret = bms_union(ExecGetUpdatedCols(relinfo, estate),
+ ExecGetForPortionOfCol(relinfo, estate),
ExecGetExtraUpdatedCols(relinfo, estate));
MemoryContextSwitchTo(oldcxt);
(Implementing that function is left as an exercise for the reader.)
> transformForPortionOfClause
> if (contain_volatile_functions_after_planning((Expr *) result->targetRange))
> ereport(ERROR,
> (errmsg("FOR PORTION OF bounds cannot contain volatile
> functions")));
>
> Need
> errcode(ERRCODE_FEATURE_NOT_SUPPORTED).
Okay.
> coerce_to_target_type function comment:
> * This is the general-purpose entry point for arbitrary type coercion
> * operations. Direct use of the component operations can_coerce_type,
> * coerce_type, and coerce_type_typmod should be restricted to special
> * cases (eg, when the conversion is expected to succeed).
>
> We should use coerce_to_target_type more, not can_coerce_type,
> coerce_type individually.
> coerce_to_target_type also handles `UNKNOWN` constant, which ensures
> the deparsing casts to the correct data type.
Including the casts when we deparse does seem like an improvement.
The patch looks good to me.
Yours,
--
Paul ~{:-)
pj@illuminatedcomputing.com
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Make ExecForPortionOfLeftovers() obey SRF protocol.
- 207cb2abcba0 19 (unreleased) landed
-
Add isolation tests for UPDATE/DELETE FOR PORTION OF
- b6ccd30d8ff6 19 (unreleased) landed
-
Add UPDATE/DELETE FOR PORTION OF
- 8e72d914c528 19 (unreleased) landed
-
Record range constructor functions in pg_range
- c257ba839718 19 (unreleased) landed
-
Add range_minus_multi and multirange_minus_multi functions
- 5eed8ce50ce9 19 (unreleased) landed
-
doc: Add section for temporal tables
- e4d8a2af07f5 19 (unreleased) landed
-
Add assertion check for WAL receiver state during stream-archive transition
- 65f4976189b6 19 (unreleased) cited