public inbox for [email protected]
help / color / mirror / Atom feedFrom: jian he <[email protected]>
To: Paul A Jungwirth <[email protected]>
Cc: Kirill Reshke <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Cc: Peter Eisentraut <[email protected]>
Subject: Re: DELETE/UPDATE FOR PORTION OF with rule system is not working
Date: Fri, 17 Apr 2026 11:20:08 +0800
Message-ID: <CACJufxFSTwzJxFYwD5mb5hSj9CvZxBh500Sza0CKoFCxB6iLsg@mail.gmail.com> (raw)
In-Reply-To: <CA+renyXkcs=5P3dd=OoyM+A=UKA7iR_zS4TAQ42F9NTv+2RNiA@mail.gmail.com>
References: <CACJufxHs1Hs00EqsZ4NbuAjmYzMzjJyP1sAj12Ne=cBsEVmQOA@mail.gmail.com>
<CALdSSPiRHCyC0fYy_E=gO+c7sbwU=7=Fz2CF-4aEa3mAe7yYAg@mail.gmail.com>
<CACJufxGjgdWnhq5X5VL9orLXyKx-ZayT_Zj_-bAKr=kf0pZ_Nw@mail.gmail.com>
<CA+renyXkcs=5P3dd=OoyM+A=UKA7iR_zS4TAQ42F9NTv+2RNiA@mail.gmail.com>
On Thu, Apr 16, 2026 at 6:40 AM Paul A Jungwirth
<[email protected]> wrote:
>
> I only have two small suggestions:
>
> Please use '[1, 11)' syntax to match the other tests.
>
> Breaking these long lines would be nice. For example:
>
> +CREATE RULE fpo_rule1 AS ON INSERT TO fpo_rule
> + DO INSTEAD UPDATE fpo_rule FOR PORTION OF f2 FROM 1 TO 4 SET f1 = 2;
>
Please check the attached v2.
V1 only has DO INSTEAD rules, adding one DO ALSO rule would make the
test coverage more robust.
--
jian
https://www.enterprisedb.com/
Attachments:
[text/x-patch] v2-0001-fix-DELETE-UPDATE-FOR-PORTION-OF-with-rules.patch (5.0K, 2-v2-0001-fix-DELETE-UPDATE-FOR-PORTION-OF-with-rules.patch)
download | inline diff:
From 2b9b04c9668c9a617e9bceebe2956133c2323ffe Mon Sep 17 00:00:00 2001
From: jian he <[email protected]>
Date: Fri, 17 Apr 2026 11:13:00 +0800
Subject: [PATCH v2 1/1] fix DELETE/UPDATE FOR PORTION OF with rules
Author: jian he <[email protected]>
Reviewed-by: Kirill Reshke <[email protected]>
Reviewed-by: Paul A Jungwirth <[email protected]>
Discussion: https://postgr.es/m/CACJufxHs1Hs00EqsZ4NbuAjmYzMzjJyP1sAj12Ne=cBsEVmQOA@mail.gmail.com
---
src/backend/nodes/nodeFuncs.c | 4 ++
src/test/regress/expected/for_portion_of.out | 55 ++++++++++++++++++++
src/test/regress/sql/for_portion_of.sql | 33 ++++++++++++
3 files changed, 92 insertions(+)
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c
index c0b880ec233..7edbd5b7225 100644
--- a/src/backend/nodes/nodeFuncs.c
+++ b/src/backend/nodes/nodeFuncs.c
@@ -2583,6 +2583,8 @@ expression_tree_walker_impl(Node *node,
{
ForPortionOfExpr *forPortionOf = (ForPortionOfExpr *) node;
+ if (WALK(forPortionOf->rangeVar))
+ return true;
if (WALK(forPortionOf->targetFrom))
return true;
if (WALK(forPortionOf->targetTo))
@@ -2591,6 +2593,8 @@ expression_tree_walker_impl(Node *node,
return true;
if (WALK(forPortionOf->overlapsExpr))
return true;
+ if (WALK(forPortionOf->rangeTargetList))
+ return true;
}
break;
case T_PartitionPruneStepOp:
diff --git a/src/test/regress/expected/for_portion_of.out b/src/test/regress/expected/for_portion_of.out
index 31f772c723d..0c0a205c44b 100644
--- a/src/test/regress/expected/for_portion_of.out
+++ b/src/test/regress/expected/for_portion_of.out
@@ -2097,4 +2097,59 @@ SELECT * FROM temporal_partitioned_5 ORDER BY id, valid_at;
(4 rows)
DROP TABLE temporal_partitioned;
+-- UPDATE/DELETE FOR PORTION OF with RULEs
+CREATE TABLE fpo_rule (f1 bigint, f2 int4range);
+INSERT INTO fpo_rule VALUES (1, '[1, 11)');
+CREATE RULE fpo_rule1 AS ON INSERT TO fpo_rule
+ DO INSTEAD UPDATE fpo_rule FOR PORTION OF f2 FROM 1 TO 4 SET f1 = 2;
+INSERT INTO fpo_rule VALUES (1, '[1, 11)');
+SELECT * FROM fpo_rule ORDER BY f1;
+ f1 | f2
+----+--------
+ 1 | [4,11)
+ 2 | [1,4)
+(2 rows)
+
+CREATE RULE fpo_rule2 AS ON INSERT TO fpo_rule
+ DO INSTEAD DELETE FROM fpo_rule FOR PORTION OF f2 FROM 1 TO 4;
+INSERT INTO fpo_rule VALUES (1, '[1, 11)');
+SELECT * FROM fpo_rule ORDER BY f1;
+ f1 | f2
+----+--------
+ 1 | [4,11)
+(1 row)
+
+CREATE RULE fpo_rule3 AS ON DELETE TO fpo_rule
+ DO INSTEAD UPDATE fpo_rule FOR PORTION OF f2 FROM 1 TO 8 SET f1 = 2;
+DELETE FROM fpo_rule FOR PORTION OF f2 FROM 1 TO 5;
+SELECT * FROM fpo_rule ORDER BY f1;
+ f1 | f2
+----+--------
+ 1 | [8,11)
+ 2 | [4,8)
+(2 rows)
+
+DROP RULE fpo_rule3 ON fpo_rule;
+CREATE RULE fpo_rule4 AS ON UPDATE TO fpo_rule
+ DO INSTEAD DELETE FROM fpo_rule FOR PORTION OF f2 FROM 6 TO 9;
+UPDATE fpo_rule FOR PORTION OF f2 FROM 4 TO 9 SET f1 = 12;
+SELECT * FROM fpo_rule ORDER BY f1;
+ f1 | f2
+----+--------
+ 1 | [9,11)
+ 2 | [4,6)
+(2 rows)
+
+DROP RULE fpo_rule4 ON fpo_rule;
+CREATE RULE fpo_rule5 AS ON UPDATE TO fpo_rule
+ DO ALSO DELETE FROM fpo_rule FOR PORTION OF f2 FROM 4 TO 6;
+UPDATE fpo_rule FOR PORTION OF f2 FROM 9 TO 10 SET f1 = 3;
+SELECT * FROM fpo_rule ORDER BY f1;
+ f1 | f2
+----+---------
+ 1 | [10,11)
+ 3 | [9,10)
+(2 rows)
+
+DROP TABLE fpo_rule;
RESET datestyle;
diff --git a/src/test/regress/sql/for_portion_of.sql b/src/test/regress/sql/for_portion_of.sql
index d4062acf1d1..fd79a9b78e7 100644
--- a/src/test/regress/sql/for_portion_of.sql
+++ b/src/test/regress/sql/for_portion_of.sql
@@ -1365,4 +1365,37 @@ SELECT * FROM temporal_partitioned_5 ORDER BY id, valid_at;
DROP TABLE temporal_partitioned;
+-- UPDATE/DELETE FOR PORTION OF with RULEs
+CREATE TABLE fpo_rule (f1 bigint, f2 int4range);
+INSERT INTO fpo_rule VALUES (1, '[1, 11)');
+
+CREATE RULE fpo_rule1 AS ON INSERT TO fpo_rule
+ DO INSTEAD UPDATE fpo_rule FOR PORTION OF f2 FROM 1 TO 4 SET f1 = 2;
+INSERT INTO fpo_rule VALUES (1, '[1, 11)');
+SELECT * FROM fpo_rule ORDER BY f1;
+
+CREATE RULE fpo_rule2 AS ON INSERT TO fpo_rule
+ DO INSTEAD DELETE FROM fpo_rule FOR PORTION OF f2 FROM 1 TO 4;
+INSERT INTO fpo_rule VALUES (1, '[1, 11)');
+SELECT * FROM fpo_rule ORDER BY f1;
+
+CREATE RULE fpo_rule3 AS ON DELETE TO fpo_rule
+ DO INSTEAD UPDATE fpo_rule FOR PORTION OF f2 FROM 1 TO 8 SET f1 = 2;
+DELETE FROM fpo_rule FOR PORTION OF f2 FROM 1 TO 5;
+SELECT * FROM fpo_rule ORDER BY f1;
+
+DROP RULE fpo_rule3 ON fpo_rule;
+CREATE RULE fpo_rule4 AS ON UPDATE TO fpo_rule
+ DO INSTEAD DELETE FROM fpo_rule FOR PORTION OF f2 FROM 6 TO 9;
+UPDATE fpo_rule FOR PORTION OF f2 FROM 4 TO 9 SET f1 = 12;
+SELECT * FROM fpo_rule ORDER BY f1;
+
+DROP RULE fpo_rule4 ON fpo_rule;
+CREATE RULE fpo_rule5 AS ON UPDATE TO fpo_rule
+ DO ALSO DELETE FROM fpo_rule FOR PORTION OF f2 FROM 4 TO 6;
+UPDATE fpo_rule FOR PORTION OF f2 FROM 9 TO 10 SET f1 = 3;
+SELECT * FROM fpo_rule ORDER BY f1;
+
+DROP TABLE fpo_rule;
+
RESET datestyle;
--
2.34.1
view thread (9+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: DELETE/UPDATE FOR PORTION OF with rule system is not working
In-Reply-To: <CACJufxFSTwzJxFYwD5mb5hSj9CvZxBh500Sza0CKoFCxB6iLsg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox