Re: SQL:2011 Application Time Update & Delete

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>
Cc: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: SQL:2011 Application Time Update & Delete
Date: 2026-04-21 06:25:06
Message-ID: CACJufxGtDyUNUnz7BnCWGdS4s1BErhbmD04wuAUKC-U-XSF36A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Apr 16, 2026 at 7:26 AM Paul A Jungwirth
<pj(at)illuminatedcomputing(dot)com> wrote:
>
> I think using INSTEAD OF triggers to replace an UPDATE/DELETE FOR
> PORTION OF is a valid use-case, but it doesn't make sense to insert
> temporal leftovers. As you say, we can't access the underlying
> storage. But also we don't know what changes the trigger actually
> made. The trigger should be responsible for leftovers, and we
> shouldn't try to add more. So I think the fix is just to skip
> inserting leftovers. I've attached a patch to do that.
>
hi.

CREATE TABLE fpo_instead_base (id int, valid_at daterange, val int);
INSERT INTO fpo_instead_base VALUES (1, '[2024-01-01,2024-12-31)', 100);
CREATE VIEW fpo_instead_view AS SELECT * FROM fpo_instead_base;
CREATE FUNCTION fpo_instead_trig_fn() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
RETURN NEW;
END;
$$;
CREATE TRIGGER fpo_instead_trig INSTEAD OF UPDATE ON fpo_instead_view
FOR EACH ROW EXECUTE FUNCTION fpo_instead_trig_fn();

UPDATE fpo_instead_view FOR PORTION OF valid_at FROM '2024-04-01' TO
'2024-08-01'
SET val = 999 WHERE id = 1
RETURNING *;

id | valid_at | val
----+-------------------------+-----
1 | [2024-01-01,2024-12-31) | 999
(1 row)

Should I expect the column `valid_at` value as [2024-04-01,2024-08-01) ?

We should also document this on doc/src/sgml/ref/update.sgml
Attached is a minor regession test enhancement for
"v2-0001-Fix-INSTEAD-OF-triggers-with-DELETE-UPDATE-FOR-PO.patch".

--
jian
https://www.enterprisedb.com/

Attachment Content-Type Size
v3-0001-misc-fix-for-V2-Fix-INSTEAD-OF-triggers-with-DELETE-UPDATE-FOR.no-cfbot application/octet-stream 3.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2026-04-21 06:30:40 Re: Add \pset options for boolean value display
Previous Message Alex Guo 2026-04-21 06:12:24 Re: [PATCH] Fix column name escaping in postgres_fdw stats import