Re: Supporting MERGE on updatable views

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Supporting MERGE on updatable views
Date: 2023-10-29 17:17:34
Message-ID: CAEZATCWHRpi426SVUHnkXGAwxcxh7oNDb1_TFZ4nOjUNJTtw9g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 28 Oct 2023 at 09:35, jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> hi.
> Excellent work! regress test passed! The code looks so intuitive!
>

Thanks for looking!

> doc/src/sgml/ref/create_view.sgml.
> Do we need to add <<command>MERGE</command> for the following sentence?
>
> If the view or any of its base
> relations has an <literal>INSTEAD</literal> rule that causes the
> <command>INSERT</command> or <command>UPDATE</command> command
> to be rewritten, then
> all check options will be ignored in the rewritten query, including any
> checks from automatically updatable views defined on top of the relation
> with the <literal>INSTEAD</literal> rule.
>

We don't want to include MERGE in that sentence, because MERGE isn't
supported on views or tables with rules, but I guess we could add
another sentence after that one, to make that clear.

> in src/backend/executor/nodeModifyTable.c line 3800: ExecModifyTable
> `
> datum = ExecGetJunkAttribute(slot,resultRelInfo->ri_RowIdAttNo,&isNull);
> .....
> oldtupdata.t_data = DatumGetHeapTupleHeader(datum);
> oldtupdata.t_len = HeapTupleHeaderGetDatumLength(oldtupdata.t_data);
> `
> In ExecGetJunkAttribute(slot,resultRelInfo->ri_RowIdAttNo,&isNull);
>
> does resultRelInfo->ri_RowIdAttNo must be 1 to make sure
> DatumGetHeapTupleHeader(datum) works?
> (I am not familiar with this part.....)

Well, it's not necessarily 1. It's whatever the attribute number of
the "wholerow" attribute is, which can vary. "datum" is then set to
the value of the "wholerow" attribute, which is the OLD tuple, so
using DatumGetHeapTupleHeader() makes sense. This relies on the code
in ExecInitModifyTable(), which sets up ri_RowIdAttNo.

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2023-10-29 17:23:00 Re: pg_resetwal tests, logging, and docs update
Previous Message Tom Lane 2023-10-29 16:57:38 Re: pg_dump not dumping the run_as_owner setting from version 16?