From 58a91650b178dffd643092b42acd0bb40fe3b0d9 Mon Sep 17 00:00:00 2001 From: Zsolt Parragi Date: Wed, 19 Aug 2026 11:04:39 +0000 Subject: [PATCH v1] 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 Discussion: https://postgr.es/m/19630-9f10ca28426295fa@postgresql.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 ca954729f1e..3056b850f73 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 -- 2.55.0