Re: FOR PORTION OF silently ignored on views with DO INSTEAD rules

From: Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: Ewan Young <kdbase(dot)hack(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: FOR PORTION OF silently ignored on views with DO INSTEAD rules
Date: 2026-09-04 03:55:42
Message-ID: CA+renyWFwAGRbXybDdc8q8zKx=zPiot9QKSDDUL9gKZpDiowCw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Sep 3, 2026 at 7:38 PM Ewan Young <kdbase(dot)hack(at)gmail(dot)com> wrote:
>
> > On the other hand a DO INSTEAD NOTHING rule is allowed. Ewan's patch
> > also allows DO INSTEAD NOTHING. That makes sense to me. Here is a
> > revised patch adding it to Ewan's tests.
>
> One small thing: the new test cases use "do nothing", which the grammar
> treats as DO ALSO NOTHING (opt_instead defaults to ALSO), so those rules
> don't replace the query and FOR PORTION OF keeps working through the
> auto-updatable path. An actual unqualified "do instead nothing" rule
> sets the instead flag in fireRules(), so the patch rejects it with the
> same error, for both UPDATE and DELETE. I think that is fine and
> consistent with the ON CONFLICT precedent you mention, but the test
> comment and the last paragraph of the commit message say the opposite,
> so they should be adjusted one way or the other. (Also, the second
> "do nothing" rule says "on update" where "on delete" was intended.)

Oh, good catch! I've updated the test. Even with "DO INSTEAD NOTHING",
ON CONFLICT does allow the rule. I think this is important, since DO
INSTEAD NOTHING has a somewhat special role as a fallback when there
are other conditional rules.[0] So I'd like to make FOR PORTION OF
work the same way. Making the fixed test pass required a very small
code change. Here is a v3 with those edits.

[0] https://www.postgresql.org/docs/current/sql-createrule.html

Yours,

--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com

Attachment Content-Type Size
v3-0001-Reject-FOR-PORTION-OF-on-views-with-unqualified-I.patch text/x-patch 8.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Lakhin 2026-09-04 04:00:00 Re: Stabilize recovery conflict stats checks in 031_recovery_conflict.pl
Previous Message Noah Misch 2026-09-04 03:51:54 Re: CREATE SCHEMA ... CREATE DOMAIN support