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

From Jeff Davis
Subject Re: MERGE ... RETURNING
Date
Msg-id d200e6b4cf17f19d804b79d02d80567cb9889c00.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 Thu, 2023-07-13 at 18:01 +0100, Dean Rasheed wrote:
> 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.

For use cases where a user could do it either way, which would you
expect to be the "typical" way (assuming we supported the new/old)?

  MERGE ... RETURNING pg_merge_action(), id, val;

or

  MERGE ... RETURNING id, OLD.val, NEW.val;

?

I am still bothered that pg_merge_action() is so context-sensitive.
"SELECT pg_merge_action()" by itself doesn't make any sense, but it's
allowed in the v8 patch. We could make that a runtime error, which
would be better, but it feels like it's structurally wrong. This is not
an objection, but it's just making me think harder about alternatives.

Maybe instead of a function it could be a special table reference like:

  MERGE ... RETURNING MERGE.action, MERGE.action_number, id, val?

Regards,
    Jeff Davis




pgsql-hackers by date:

Previous
From: Farias de Oliveira
Date:
Subject: In Postgres 16 BETA, should the ParseNamespaceItem have the same index as it's RangeTableEntry?
Next
From: Gurjeet Singh
Date:
Subject: Re: Fix search_path for all maintenance commands