From c7e34c31e844b2234fa57fef12ae37f30c8f5a9b Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 21 Aug 2026 13:55:58 +0200 Subject: [PATCH] Fix error code for null FOR PORTION OF target When the target expression of FOR PORTION OF (...) evaluated to NULL, ExecInitModifyTable raised an error without an errcode, so clients got the internal error code XX000 for a user-reachable condition. Oversight in commit 8e72d914c52. To fix, report ERRCODE_NULL_VALUE_NOT_ALLOWED, and reword the message to "FOR PORTION OF target must not be null", matching similar executor messages such as "frame starting offset must not be null". Bug: #19630 Reported-by: Zheng Wang Reported-by: Yanjie Zhao Reported-by: Yiyang Liu Author: Zsolt Parragi Discussion: https://www.postgresql.org/message-id/flat/19630-9f10ca28426295fa%40postgresql.org --- src/backend/executor/nodeModifyTable.c | 5 +++-- src/test/regress/expected/for_portion_of.out | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 9a1c0992bfe..5681505d31c 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -5645,8 +5645,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) */ if (isNull) ereport(ERROR, - (errmsg("FOR PORTION OF target was null")), - executor_errposition(estate, forPortionOf->targetLocation)); + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("FOR PORTION OF target must not be null"), + executor_errposition(estate, forPortionOf->targetLocation))); /* Create state for FOR PORTION OF operation */ diff --git a/src/test/regress/expected/for_portion_of.out b/src/test/regress/expected/for_portion_of.out index a6cb1ba8380..1a53e549de0 100644 --- a/src/test/regress/expected/for_portion_of.out +++ b/src/test/regress/expected/for_portion_of.out @@ -407,7 +407,7 @@ UPDATE for_portion_of_test FOR PORTION OF valid_at (NULL) SET name = 'one^3' WHERE id = '[1,2)'; -ERROR: FOR PORTION OF target was null +ERROR: FOR PORTION OF target must not be null LINE 2: FOR PORTION OF valid_at (NULL) ^ -- Updating with a direct target of empty does nothing @@ -884,7 +884,7 @@ LINE 2: FOR PORTION OF valid_at (4) DELETE FROM for_portion_of_test FOR PORTION OF valid_at (NULL) WHERE id = '[1,2)'; -ERROR: FOR PORTION OF target was null +ERROR: FOR PORTION OF target must not be null LINE 2: FOR PORTION OF valid_at (NULL) ^ -- Deleting with a direct target of empty does nothing @@ -1971,7 +1971,7 @@ UPDATE for_portion_of_test2 FOR PORTION OF valid_at (NULL) SET name = 'one^3' WHERE id = '[1,2)'; -ERROR: FOR PORTION OF target was null +ERROR: FOR PORTION OF target must not be null LINE 2: FOR PORTION OF valid_at (NULL) ^ -- Updating with empty does nothing @@ -2035,7 +2035,7 @@ LINE 2: FOR PORTION OF valid_at (4) DELETE FROM for_portion_of_test2 FOR PORTION OF valid_at (NULL) WHERE id = '[2,3)'; -ERROR: FOR PORTION OF target was null +ERROR: FOR PORTION OF target must not be null LINE 2: FOR PORTION OF valid_at (NULL) ^ -- Deleting with empty does nothing