Re: [HACKERS] Allow INSTEAD OF DELETE triggers to modify the tuple for RETURNING

From: Rahila Syed <rahilasyed90(at)gmail(dot)com>
To: marko(at)joh(dot)to
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, jian he <jian(dot)universality(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, Haribabu Kommi <kommi(dot)haribabu(at)gmail(dot)com>, Aleksander Alekseev <aleksander(at)timescale(dot)com>
Subject: Re: [HACKERS] Allow INSTEAD OF DELETE triggers to modify the tuple for RETURNING
Date: 2024-09-19 08:41:20
Message-ID: CAH2L28vbODgMnn-j0coRbtgMGWKiwFtuxXh2EEPNzALJC5L7GA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

> So I'm suggesting to change this behavior and allow INSTEAD OF DELETE
> triggers to modify the OLD tuple and use that for RETURNING instead of
> returning the tuple in planSlot. Attached is a WIP patch implementing
that.
>
I am trying to understand the basic idea behind the change. What is the
use-case for allowing the OLD tuple to be modified in the INSTEAD of DELETE
triggers.
AFAIU no matter what we return from the trigger OLD/NEW or NULL, the delete
operation is skipped, so what is the point of modifying the OLD row in your
test
for example.

If the requirement is to show the recent row in the returning clause, is
fetching the
row from heap and copying into the returning slot not enough?

In the tests shown as follows, inspite of the output showing 'DELETE 1',
no row is actually deleted from the table or the view. Probably this
is an existing behavior but I think this is misleading.

```
DELETE FROM test_ins_del_view where a = 1 returning a;
NOTICE: old.a 4
a
---
4
(1 row)

DELETE 1
```

FWIW, it might be good to include in tests the example
to demonstrate the problem regarding the concurrent transactions,
one of which is modifying the row and the other returning it
after attempting DELETE.

Thank you,
Rahila Syed

On Fri, Mar 15, 2024 at 7:57 PM Aleksander Alekseev <
aleksander(at)timescale(dot)com> wrote:

> Hi,
>
> > it took me a while to figure out why the doc build fails.
> >
> > [...]
> >
> > Anyway, based on your patch, I modified it, also added a slightly more
> complicated test.
>
> Thank you for keeping the patch up-to-date. Unfortunately, it seems to
> be needing another rebase, according to cfbot.
>
> Best regards,
> Aleksander Alekseev (wearing co-CFM hat)
>
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrei Lepikhov 2024-09-19 08:44:25 Re: Incremental Sort Cost Estimation Instability
Previous Message Amit Kapila 2024-09-19 08:40:57 Re: Pgoutput not capturing the generated columns