1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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 8e72d914c5.

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 <hackerzheng666@gmail.com>
Reported-by: Yanjie Zhao
Reported-by: Yiyang Liu
Author: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://www.postgresql.org/message-id/flat/19630-9f10ca28426295fa%40postgresql.org
This commit is contained in:
Peter Eisentraut
2026-08-21 13:55:58 +02:00
parent a1bb92fb25
commit c16a1b4f2c
2 changed files with 7 additions and 6 deletions

View File

@@ -5645,8 +5645,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
*/ */
if (isNull) if (isNull)
ereport(ERROR, ereport(ERROR,
(errmsg("FOR PORTION OF target was null")), (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
executor_errposition(estate, forPortionOf->targetLocation)); errmsg("FOR PORTION OF target must not be null"),
executor_errposition(estate, forPortionOf->targetLocation)));
/* Create state for FOR PORTION OF operation */ /* Create state for FOR PORTION OF operation */

View File

@@ -407,7 +407,7 @@ UPDATE for_portion_of_test
FOR PORTION OF valid_at (NULL) FOR PORTION OF valid_at (NULL)
SET name = 'one^3' SET name = 'one^3'
WHERE id = '[1,2)'; 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) LINE 2: FOR PORTION OF valid_at (NULL)
^ ^
-- Updating with a direct target of empty does nothing -- 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 DELETE FROM for_portion_of_test
FOR PORTION OF valid_at (NULL) FOR PORTION OF valid_at (NULL)
WHERE id = '[1,2)'; 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) LINE 2: FOR PORTION OF valid_at (NULL)
^ ^
-- Deleting with a direct target of empty does nothing -- Deleting with a direct target of empty does nothing
@@ -1971,7 +1971,7 @@ UPDATE for_portion_of_test2
FOR PORTION OF valid_at (NULL) FOR PORTION OF valid_at (NULL)
SET name = 'one^3' SET name = 'one^3'
WHERE id = '[1,2)'; 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) LINE 2: FOR PORTION OF valid_at (NULL)
^ ^
-- Updating with empty does nothing -- Updating with empty does nothing
@@ -2035,7 +2035,7 @@ LINE 2: FOR PORTION OF valid_at (4)
DELETE FROM for_portion_of_test2 DELETE FROM for_portion_of_test2
FOR PORTION OF valid_at (NULL) FOR PORTION OF valid_at (NULL)
WHERE id = '[2,3)'; 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) LINE 2: FOR PORTION OF valid_at (NULL)
^ ^
-- Deleting with empty does nothing -- Deleting with empty does nothing