agora inbox for pgsql-bugs@postgresql.org  
help / color / mirror / Atom feed
BUG #19630: FOR PORTION OF crashes with XX000 when target range is NULL
3+ messages / 3 participants
[nested] [flat]

* BUG #19630: FOR PORTION OF crashes with XX000 when target range is NULL
@ 2026-08-19 03:51  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2026-08-19 03:51 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: hackerzheng666@gmail.com

The following bug has been logged on the website:

Bug reference:      19630
Logged by:          Zheng Hacker
Email address:      hackerzheng666@gmail.com
PostgreSQL version: 19beta3
Operating system:   Linux x86_64
Description:        

PostgreSQL version: 20devel (commit bdbf662, 2026-08-19)
  OS: Linux x86_64
  
  When a DELETE/UPDATE ... FOR PORTION OF receives a NULL range
  target, it hits elog(ERROR) without errcode() in nodeModifyTable.c,
  producing SQLSTATE XX000 instead of a proper error.
  
  Reproducer:
  
  CREATE TABLE t (
    id int4range NOT NULL,
    valid_at daterange NOT NULL,
    name text NOT NULL,
    CONSTRAINT t_pk PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
  );
  INSERT INTO t (id, valid_at, name)
    VALUES ('[1,2)', '[2018-01-02,2020-01-01)', 'one');
    
  DELETE FROM t FOR PORTION OF valid_at (NULL) WHERE id = '[1,2)';
  -- ERROR: XX000: FOR PORTION OF target was null
  -- LOCATION: ExecInitModifyTable, nodeModifyTable.c:5647
  
  Expected: a proper SQLSTATE (e.g. 22004 null_value_not_allowed).

  Found by automated SQL fuzzing.
  Credit: Zheng Wang, Yanjie Zhao, Yiyang Liu








^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #19630: FOR PORTION OF crashes with XX000 when target range is NULL
@ 2026-08-19 11:11  Zsolt Parragi <zsolt.parragi@percona.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Zsolt Parragi @ 2026-08-19 11:11 UTC (permalink / raw)
  To: hackerzheng666@gmail.com; pgsql-bugs@lists.postgresql.org

Thank you for the bug report!

The attached patch fixes the issue and improves the error message to
match other similar messages.

Attachments:

  [application/octet-stream] v1-0001-Fix-error-code-for-null-FOR-PORTION-OF-target.patch (3.3K, ../../CAN4CZFPsGAs3x5oBi5YiUyFdJgJrxfp=Hi3xscq_Y-HLMCs1kQ@mail.gmail.com/2-v1-0001-Fix-error-code-for-null-FOR-PORTION-OF-target.patch)
  download | inline diff:
From 58a91650b178dffd643092b42acd0bb40fe3b0d9 Mon Sep 17 00:00:00 2001
From: Zsolt Parragi <zsolt.parragi@percona.com>
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 <hackerzheng666@gmail.com>
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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #19630: FOR PORTION OF crashes with XX000 when target range is NULL
@ 2026-08-21 12:16  Peter Eisentraut <peter@eisentraut.org>
  parent: Zsolt Parragi <zsolt.parragi@percona.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Peter Eisentraut @ 2026-08-21 12:16 UTC (permalink / raw)
  To: Zsolt Parragi <zsolt.parragi@percona.com>; hackerzheng666@gmail.com; pgsql-bugs@lists.postgresql.org

On 19.08.26 13:11, Zsolt Parragi wrote:
> Thank you for the bug report!
> 
> The attached patch fixes the issue and improves the error message to
> match other similar messages.

Committed, thanks.






^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-08-21 12:16 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-19 03:51 BUG #19630: FOR PORTION OF crashes with XX000 when target range is NULL PG Bug reporting form <noreply@postgresql.org>
2026-08-19 11:11 ` Zsolt Parragi <zsolt.parragi@percona.com>
2026-08-21 12:16   ` Peter Eisentraut <peter@eisentraut.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox