Re: MERGE ... RETURNING - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: MERGE ... RETURNING
Date
Msg-id CAEZATCUHtYtBX5wVB4h8+06nMcTJat2DVhScG4EUHiTFRH7E+Q@mail.gmail.com
Whole thread Raw
In response to Re: MERGE ... RETURNING  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: MERGE ... RETURNING
List pgsql-hackers
On Thu, 13 Jul 2023 at 17:01, Jeff Davis <pgsql@j-davis.com> wrote:
>
> MERGE can end up combining old and new values in a way that doesn't
> happen with INSERT/UPDATE/DELETE. For instance, a "MERGE ... RETURNING
> id" would return a mix of NEW.id (for INSERT/UPDATE actions) and OLD.id
> (for DELETE actions).
>

Right, but allowing OLD/NEW.colname in the RETURNING list would remove
that complication, and it shouldn't change how a bare colname
reference behaves.

> The pg_merge_action() can differentiate the old and new values, but
> it's a bit more awkward.
>

For some use cases, I can imagine allowing OLD/NEW.colname would mean
you wouldn't need pg_merge_action() (if the column was NOT NULL), so I
think the features should work well together.

Regards,
Dean



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: remaining sql/json patches
Next
From: Dean Rasheed
Date:
Subject: Re: MERGE ... RETURNING