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

From Jeff Davis
Subject Re: MERGE ... RETURNING
Date
Msg-id 1223124bf7d13181ddb1a95aa81f72ed657682e1.camel@j-davis.com
Whole thread Raw
In response to Re: MERGE ... RETURNING  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: MERGE ... RETURNING
List pgsql-hackers
On Mon, 2023-01-09 at 12:29 +0000, Dean Rasheed wrote:
> > Would it be feasible to allow specifying old.column or new.column?
> > These would always be NULL for INSERT and DELETE respectively but
> > more useful with UPDATE. Actually I've been meaning to ask this
> > question about UPDATE … RETURNING.
> >
>
> I too have wished for the ability to do that with UPDATE ...
> RETURNING, though I'm not sure how feasible it is.
>
> I think it's something best considered separately though. I haven't
> given any thought as to how to make it work, so there might be
> technical difficulties. But if it could be made to work for UPDATE,
> it
> shouldn't be much more effort to make it work for MERGE.

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).

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

I'm fine considering that as a separate patch, but it does seem worth
discussing briefly here.

Regards,
    Jeff Davis




pgsql-hackers by date:

Previous
From: Pavel Luzanov
Date:
Subject: Re: psql: Add role's membership options to the \du+ command
Next
From: Daniel Gustafsson
Date:
Subject: Re: sslinfo extension - add notbefore and notafter timestamps